This code changes a string in 1 text file in python
Thanks
I also tried this.It runs without errors but changes nothing in the text files.
I ran the code under the directory under which the files are stored.
s = open("sample.txt").read() s = s.replace('abcd', 'efgh') f = open("mount.txt", 'w') f.write(s) f.close()How do I change a single string ex: from abcd to efgh in 100's of text files under a single directory.
Thanks
I also tried this.It runs without errors but changes nothing in the text files.
I ran the code under the directory under which the files are stored.
import glob,os,fileinput from glob import glob for filename in glob('*.LIC'): with fileinput.FileInput(filename, inplace=True, backup='.bak') as file: for line in file: print(line.replace('abcd', 'efgh'), end='')