Splitting on '^' ?
rurpy at yahoo.com
rurpy at yahoo.com
Fri Aug 14 18:01:29 EDT 2009
On Aug 14, 2:23 pm, kj <no.em... at please.post> wrote:
> Sometimes I want to split a string into lines, preserving the
> end-of-line markers. In Perl this is really easy to do, by splitting
> on the beginning-of-line anchor:
>
> @lines = split /^/, $string;
>
> But I can't figure out how to do the same thing with Python. E.g.:
Why not this?
>>> lines = 'spam\nham\neggs\n'.splitlines (True)
>>> lines
['spam\n', 'ham\n', 'eggs\n']
More information about the Python-list
mailing list