Sorry, I meant lines in line in the below: f = open(filename) lines = f.readlines() f.close() # num for some line number >>lines[num] = "String" f = open(filename) f.writelines(lines) f.close()
******************************************************************* Hello, I was wondering if it is possible to write a string to a specific line in a file without reading in the whole file in as the below. ___________________________________________________________________ f = open(filename) lines = f.readlines() f.close() # num for some line number line[num] = "String" f = open(filename) f.writelines(lines) f.close() ____________________________________________________________________ Writing directly to the line number would be ideal. Some thing like: f.write(line number, string) if there is a function like that. Or would the best way to do line replacement be through iteration. __________________________________________________________________ for line in open(filename): # write to current line??? _________________________________________________________________ Thank you. Best regards, Tak _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor