kah wrote:
How do I change a line in a file??

For example I have the follwing text in my file:

line1
line2
line3
line4

How do I replace 'line2' with 'newline'. Since the write operation in
python will  overwrite everything.

This is the best I can figure out what you mean:

lines = []
for line in file("myfile.txt"):
    if line == "line2\n":
        line = "newline\n"
    lines.append(line)

file("myfile.txt", "W").writelines(lines)

--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to