Answers for "replace character in file python"

3

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()
Posted by: Guest on October-06-2020
0

replace characters in string python

>>> a = '&#'
>>> print a.replace('&', r'\&')
\&#
>>> print a.replace('#', r'\#')
&\#
>>>
Posted by: Guest on February-09-2021

Code answers related to "replace character in file python"

Python Answers by Framework

Browse Popular Code Answers by Language