Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python replace string in file

#input file
fin = open("data.txt", "rt")
#output file to write the result to
fout = open("out.txt", "wt")
#for each line in the input file
for line in fin:
	#read replace the string and write to output file
	fout.write(line.replace('pyton', 'python'))
#close input and output files
fin.close()
fout.close()
Source by pythonexamples.org #
 
PREVIOUS NEXT
Tagged: #python #replace #string #file
ADD COMMENT
Topic
Name
1+3 =