Python thinks file is empty

kyosohma at gmail.com kyosohma at gmail.com
Mon Nov 5 16:35:43 CET 2007


On Nov 5, 9:19 am, loial <jldunn2... 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()
>
> But whenever I try to do anything with the file in python it finds  no
> data. I am trying ftp, copying the file...the resultant file is always
> 0 bytes, although if I look at the original file on the unix command
> line, its fine
>
> e.g.
>
> shutil.copyfile('/home/john/myfile', '/home/john/myfile2')
>
> Any ideas what the problem is?

This works for me on Windows. I can open the file I create in notepad
and it has the correct text within it. I also tried using shutil to
copy it and that worked too.

How are you opening the file in Python? If you open it using the 'w'
flag, it'll just erase the file...

Mike




More information about the Python-list mailing list