I'm trying to read a text from a text file, read lines, delete lines that contain specific string (in this case 'bad' and 'naughty'). The code I wrote goes like this:
infile = file('./oldfile.txt')
newopen = open('./newfile.txt', 'w')
for line in infile :
if 'bad' in line:
line = line.replace('.' , '')
if 'naughty' in line:
line = line.replace('.', '')
I wrote like this but it doesn't work out.
One thing important is if the content of the text was like this:
I don't want the output to have empty lines. so not like:
but like this:
What should I edit from my code on the above?