Samstag, 13. August 2016

python remove empty lines from string


How about:
text = os.linesep.join([s for s in text.splitlines() if s])
where text is the string with the possible extraneous lines?

http://stackoverflow.com/questions/1140958/whats-a-quick-one-liner-to-remove-empty-lines-from-a-python-string/1140966#1140966

Keine Kommentare:

Kommentar veröffentlichen