Here is my code:
with open('locations.txt', 'r') as f, open('output.txt', 'w') as fo:
for line in f:
fo.write(line.replace('test'[:-1], ''))
I have a file with multiple lines of text:
This is a test the cat jumped around
This is another test the dog jumped under
This is a third test the cow jumped over
I want to be able to open the text file, and remove everything on each line after the word 'test'. So result would look like:
This is a test
This is another test
This is a third test
I am trying to use .replace() but using the paramter of -1 it just removed everything but the last letter in test. I am really not sure how to have the word 'test' be the input then have it remove the rest of the string after that on each line.