I want to be able to open a file, locate a specific string and then append a string to that specific line.
So far, I have:
import errno
import glob
path = '/path/to/key_files/*.txt'
SubjectName = 'predetermined'
files = glob.glob(path)
for filename in files:
try:
with open(filename, 'r+') as f:
for line in f:
if SubjectName in line:
print(line)
except IOError as exc:
if exc.errno != errno.EISDIR:
raise
Which prints a line from the text file containing the string I specified, so I know all the code works in terms of locating the correct line. I now want to add the string ',--processed\n' to the end of the located line, as opposed to appending it to the very end of the file. Is there a way to do this?