Alan Gauld wrote: > "Diana Hawksworth" <[EMAIL PROTECTED]> wrote > >> How do I find a particular name, change the score and then save >> the changes back to the text file again?? > > iterate over the file checking (and modifying) each line > write the line back out: > > Pseudo code > > Out = open('foo.txt','w') BEWARE: this will truncate the file immediately, erasing all the data in it!!!
Use a temporary file and after you finish processing the data in the original file, move (or rename) the temporary file to the original name. > for line in file('foo.txt'): > if 'somestring' in line: > line = 'I changed it\n' > Out.write(line) > > Out.close() > > You will find much more on this in my file handling topic in my > tutorial. > > Ziyad. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor