I had several print() statements in my code. I want run the code overnight and have them write to file. I tried redirecting output to file as:
python mycode.py >> log.txt
While python process is running, I cannot see anything written to file. When I kill the process and open the log file, I find the output in it.
Similar behavior was seen when I explicitlys specified file handle in the every print statement:
output_file = open('log.txt','w')
print('blablabla', file=output_file)
How can I make print
to write the file immediately? Am I missing anything?