Can we change a particular word in text file with replace(), after opening the file with open() and then print the desired result in output?
I tried this, ouput was not what i expected. Kindly correct if something is missing :
fhandle=open(‘mbox.txt’)
for q in fhandle:
if q.startswith(‘3rd’):
q.replace(‘3rd’,‘This’)
print(q)
OUTPUT:
This is a line.
This is another line.
3rd line is an exception.
This is the fourth line.