Splitting on '^' ?

John Yeung gallium.arsenide at gmail.com
Sun Aug 16 20:35:52 CEST 2009

On Aug 16, 1:09 pm, kj <no.em... at please.post> wrote:
> And .splitlines seems to be able to handle all
> "standard" end-of-line markers without any special
> direction (which, ironically, strikes
> me as a *little* Perlish, somehow):

It's Pythonic.  Universal newline-handling for text has been a staple
of Python for as long as I can remember (very possibly since the very

> >>> "spam\015\012ham\015eggs\012".splitlines(True)
> ['spam\r\n', 'ham\r', 'eggs\n']
> Amazing.  I'm not sure this is the *best* way to do
> this in general (I would have preferred it, and IMHO
> it would have been more Pythonic, if .splitlines
> accepted an additional optional argument [...]).

I believe it's the best way.  When you can use a string method instead
of a regex, it's definitely most Pythonic to use the string method.

I would argue that this particular string method is Pythonic in
design.  Remember, Python strives not only for explicitness, but
simplicity and ease of use.  When dealing with text, universal
newlines are much more often than not simpler and easier for the


More information about the Python-list mailing list