The Split String Function - How to preserve whitespace?

daftspaniel at gmail.com daftspaniel at gmail.com
Sat Jul 8 15:55:38 EDT 2006


Hi Folks,

I am trying to scan the lines in the string text:
        lines = text.split('\n')

seemed to do the job but has the side effect of stripping the
whitespace. As I am reading Python source in this text and checking
identation this is a bit annoying :-)

How can I stop this happening? Doesn't look like an option from the
documents. Do I have to use a regexp (scary unchartered stuff for
me...)?

Thanks,
Davy Mitchell

The Good Ol' Blog
http://www.latedecember.com/sites/personal/davy/




More information about the Python-list mailing list