write a text file in Python, line by line
I need to write a text file, line by line. This code is printing line by
line, but not storing properly,only the last line is stored in the
result.txt file.
import re
import fileinput
for line in fileinput.input("test.txt"):
new_str = re.sub('[^a-zA-Z0-9\n\.]'," ", line)
print new_str
open('result.txt', 'w').write(new_str)
Thanks in advance
No comments:
Post a Comment