How to redirect 'print' output to a file using python?

后端 未结 11 1138
既然无缘
既然无缘 2020-11-22 17:05

I want to redirect the print to a .txt file using python. I have a \'for\' loop, which will \'print\' the output for each of my .bam file while I want to redirect ALL these

11条回答
  •  暖寄归人
    2020-11-22 17:35

    If you are using Linux I suggest you to use the tee command. The implementation goes like this:

    python python_file.py | tee any_file_name.txt
    

    If you don't want to change anything in the code, I think this might be the best possible solution. You can also implement logger but you need do some changes in the code.

提交回复
热议问题