Workingwithtext: Difference between revisions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
Replacing | Replacing words and output in txt | ||
<source lang="python"> | <source lang="python"> | ||
#import time | #import time | ||
f = open(' | f = open('filename.txt') | ||
print f | print f | ||
out = open(' | out = open('newfilename.txt', 'w') | ||
for line in f: | for line in f: | ||
line = line.strip().lower() | line = line.strip().lower() | ||
text = line.replace(' | text = line.replace('old' , 'new') | ||
#time.sleep(.2) | #time.sleep(.2) | ||
print text | print text |
Latest revision as of 23:05, 18 November 2013
Replacing words and output in txt
#import time
f = open('filename.txt')
print f
out = open('newfilename.txt', 'w')
for line in f:
line = line.strip().lower()
text = line.replace('old' , 'new')
#time.sleep(.2)
print text
out.write(text)
out.close()