how to write a line in a text file

wittempj@hotmail.com martin.witte at gmail.com
Mon Jul 25 15:57:55 EDT 2005


A recipe is
* open your file for reading: f = open('filename.txt', 'r')
* read all lines in a list: content = f.readlines()
* close the file: f.close()
* set the third element in the list to something else: content[2] =
'Blahdiblah'
* re-open the file for writing: f = open('filename.txt', 'w')
* write the list to the file: f.writelines(content)
* close the file: f.close()




More information about the Python-list mailing list