Workingwithtext: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "<source lang="python"> #import time f = open('facebookdatapolicy.txt') print f out = open('newfilenikos.txt', 'w') #saveas for line in f: line = line.strip().lower() text ...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Replacing words  and output in txt
<source lang="python">
<source lang="python">
#import time
#import time
f = open('facebookdatapolicy.txt')
f = open('filename.txt')
print f
print f


out = open('newfilenikos.txt', 'w') #saveas
out = open('newfilename.txt', 'w')  


for line in f:
for line in f:
line = line.strip().lower()
line = line.strip().lower()
text = line.replace('facebook' , 'THE WORLD WE CREATED FOR YOU TO FIT YOUR SELF COMFORTABLY')
text = line.replace('old' , 'new')
#time.sleep(.2)
#time.sleep(.2)
print text  
print text  

Latest revision as of 00:05, 19 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()