Skip to content Skip to sidebar Skip to footer

Python - Reading From A Text File That Is Being Written In Windows

I am using Windows 7, Python 2.7. I am trying to write to a text file with one file ID in one program that continues writing new data/numbers for several minutes. In a separate pro

Solution 1:

This might be caused by buffering in program 1. You can try flushing the output in program 1 after each write:

fid.write(str(i) + "\n")
fid.flush()

Another thing you can try is to run the Python interpreter in unbuffered mode for program 1. Use the python -u option.

Also, do you need to open the file for update (mode r+) in program 2? If you just want to read it, mode r is sufficient, or you can omit the mode when calling open().

Post a Comment for "Python - Reading From A Text File That Is Being Written In Windows"