ignoring or replacing white lines in a diff
Peter Otten
__peter__ at web.de
Fri Jan 15 05:20:37 EST 2016
Adriaan Renting wrote:
> - print line, did remove the extra newlines, but didn't get rid of the
> blank lines.
You mean you found that
import fileinput
for line in fileinput.FileInput("test.xml", inplace=True):
if line.strip():
print line,
does not remove all blank lines?
If the file contains lone carriage returns try "universal newlines" mode:
for line in fileinput.FileInput("test.xml", inplace=True, mode="U"):
if line.strip():
print line,
More information about the Python-list
mailing list