Skip to content
Advertisement

how to delete the entire line if line has specific word in python

i have a .txt file like this:

JavaScript

and i want to delete the entire line that include “pen” word

like this:

JavaScript

and i tried this

JavaScript

—————————AND—————————— how i delete just the “pen” word in the .txt file

Advertisement

Answer

First you need to put the result on another file (myfile2) and you need to print on this file the lines thats not contain “pen”.

JavaScript

Second to just substitute the word use replace(,)

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement