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

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -