I want to delete a specific line containing a specific string in Python.
Suppose I have a file fruit.txt having the following content:
Now, I want to delete Apple from that file and I have made this following function:
fname = 'fruit.txt'
f = open(fname)
output = 
for line in f:
if not "Apple" in line:
f = open(fname, 'w')
It gives this output;
So, the main problem is that the function is deleting both Apple and Apple1 but I only want to delete “Apple”.
The required should be like this:
How should I change my function so that it gives the correct output?