[Tutor] read, write to file

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon Jul 21 17:35:15 2003


On Mon, 21 Jul 2003, Vernon Miller wrote:

> I spend all day trying to get this to work
>
> f=open('C:/Python22/Tools/tmp/workfile.txt', 'w')
> f.write('This is the first line of the file')

Hi Vernon,


Oh!  Don't forget to close() the file.  This actually is important,
because some operating systems will delay from actually writing the bits
to disk until the file is explicitely closed.


With the fix, your code might look like this:

###
f = open('C:/Python22/Tools/tmp/workfile.txt', 'w')
f.write('This is the first line of the file')
f.close()
###


Hope this fixes the problem!