python get data from an already opened file -


f=open("vmi","w") f.write("asdf") import os os.path.getsize("vmi") #0 byte f.close() os.path.getsize("vmi") # 4 bytes 

where can find lost 4 bytes, on program execution, before file closed?

you try flush out data first:

f.flush() 

why need this? well, os try buffer writes files performance reasons - lot slower write 1024 bytes 1 @ time write out whole buffer. so, whenever working file / pipe / socket kind of thing, keep in mind might buffering writes , need flush first.

when closed file, flushed automatically.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -