Can I Read New Data From An Open File Without Reopening It?
Consider having a file test.txt with some random text in it. Now we run the following code: f = open('test.txt', 'r') f.read() Now we append data onto test.txt from some other pro
Solution 1:
If you read from f
again, you will get more data.
f = open('my_file')
print(f.read())
# in bash: echo 'more data' >> my_file
print(f.read())
f
is basically a file handle with a position, reading from it again will just continue to read from whatever the position currently is.
This can also be affected by what is modifying the file. Many text editors will save to a separate file first, then copy over the original. If this happens, you will not see the changes as they are in a new file. You many be able to continue using the existing file, but as soon as you close it the OS will finalize the delete.
Post a Comment for "Can I Read New Data From An Open File Without Reopening It?"