f=open("vmi","w")
f.write("asdf")
import os
os.path.getsize("vmi")
#0 byte
f.close()
os.path.getsize("vmi")
# 4 bytes
Where I can find lost 4 bytes,
on program execution, before file is closed?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could try to flush out the data first:
Why would you need to do this? Well, the OS will try to buffer writes to files for performance reasons – it is a lot slower to write 1024 bytes one at a time than just write out the whole buffer. So, whenever you are working with a file / pipe / socket kind of thing, keep in mind that it might be buffering writes and that you will need to
flushfirst.When you closed the file, it was flushed automatically.