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

后端 未结 11 1122
既然无缘
既然无缘 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:30

    Something to extend print function for loops

    x = 0
    while x <=5:
        x = x + 1
        with open('outputEis.txt', 'a') as f:
            print(x, file=f)
        f.close()
    

提交回复
热议问题