Python thinks file is empty

Tim Roberts timr at probo.com
Tue Nov 6 06:32:00 CET 2007


loial <jldunn2000 at googlemail.com> wrote:
>
>I am writing a file in python with writelines
>
>f = open('/home/john/myfile',"w")
>f.writelines("line1\n")
>f.writelines("line2\n")
>f.close()

Are you absolutely sure it looks like that?  If you wrote this:

   f.close

(as reformed VB programmers tend to write) it would run without error or
warning, but the file would not actually be closed.  The data would be hung
up the buffer, and the file would be 0 length.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list