The Split String Function - How to preserve whitespace?

D

daftspaniel

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/
 
J

Just

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...)?
['a\n', 'b\n', 'c\n']

Just
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top