Reputation: 5843
Suppose I have the following python script:
with open(fileName, "a") as myfile:
myfile.write(myData)
I don't really know how file buffers work, but I am aware of the fact that characters may queue up and not actually be written to file immediately.
My question is: once the python script ends, will the file DEFINITELY contain myData? I.e., if I'm calling this from the command line as python script.py
, then when I get control again at the command line, will the file reflect my changes 100% of the time?
If it matters (maybe this is specific to the filesystem used?), I'll be running this on a 64-bit Windows machine (running Windows 7).
Upvotes: 2
Views: 1251
Reputation: 5830
Yes. It is actually flushed on close which is guaranteed to happen when you leave your with
block.
Upvotes: 3