how to split text into lines?

Chris cwitts at gmail.com
Thu Jul 31 08:59:50 CEST 2008


On Jul 31, 7:26 am, alex23 <wuwe... at gmail.com> wrote:
> kj wrote:
> > Sorry, I should have googled this first.  I just found splitlines()...
>
> > Still, for my own edification, is there a way to achieve the same
> > effect using re.split?
>
> re.split(os.linesep, <string>) works the same as <string>.splitlines()
>
> Neither retain the EOL for each line, though. The only way I'm aware
> of is to re-add it:
>
> [s+os.linesep for s in re.split(os.linesep, <string>)]
>
> Was that what you were after?

or what about 'string'.splitlines(True) as that retains newline
characters. ;)



More information about the Python-list mailing list