Nico Grubert
2005-09-22 12:52:06 UTC
Hi there,
I would like to open an existing file that contains some lines of text
in order to append a new line at the end of the content.
Does f = open('/tmp/myfile', 'w') overwrite the existing file or does
f.writelines('456') replace the first line in the existing file?
Nico
I would like to open an existing file that contains some lines of text
in order to append a new line at the end of the content.
f = open('/tmp/myfile', 'w') #create new file for writing
f.writelines('123') #write first line
f.close()
f = open('/tmp/myfile', 'w') #open existing file to append new line
f.writelines('456')
f.close()
f = open('/tmp/myfile', 'r') # open file for reading
f.read()
'456'f.writelines('123') #write first line
f.close()
f = open('/tmp/myfile', 'w') #open existing file to append new line
f.writelines('456')
f.close()
f = open('/tmp/myfile', 'r') # open file for reading
f.read()
f.read()
'123\n456\n'Does f = open('/tmp/myfile', 'w') overwrite the existing file or does
f.writelines('456') replace the first line in the existing file?
Nico