SyntaxFix
Write A Post
Hire A Developer
Questions
You could simply not include the line into the new file instead of doing replace.
for line in infile : if 'bad' not in line and 'naughty' not in line: newopen.write(line)