0
Removing lines from text files
Does anyone have ideas on how to remove a line containing a specific character from a text file using python? Say for example, that I want to remove all lines from a text file that contain the letter 'z'. I tried using readlines() and then removing those lines which contain 'z' from the list but these changes are obviously not reflected on the file itself. Is there another way to do this?
1 Resposta
+ 1
you should readlines(), filter lines to get only lines to be keeping, and then save either in a new file or in initial file... (technically you make a new file in both cases)