By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,547 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,547 IT Pros & Developers. It's quick & easy.

The Split String Function - How to preserve whitespace?

P: n/a
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/

Jul 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <11**********************@35g2000cwc.googlegroups. com>,
"da*********@gmail.com" <da*********@gmail.comwrote:
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\nb\nc\n".splitlines(True)
['a\n', 'b\n', 'c\n']

Just
Jul 8 '06 #2

P: n/a
Just wrote:
>>"a\nb\nc\n".splitlines(True)
['a\n', 'b\n', 'c\n']
Genius - Thanks alot for the quick response !! :-)

Thanks,
Davy Mitchell

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

Jul 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.