Re: how to split text into lines?

2008-07-31 Thread alex23
Chris wrote: > or what about 'string'.splitlines(True) as that retains newline > characters. ;) Okay, you win :) Man, you'd think with the ease of object introspection I'd have at least looked at its docstring :) Cheers, Chris! -- http://mail.python.org/mailman/listinfo/python-list

Re: how to split text into lines?

2008-07-31 Thread Chris
On Jul 31, 7:26 am, alex23 <[EMAIL PROTECTED]> 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, ) works the same as .splitlines()

Re: how to split text into lines?

2008-07-30 Thread alex23
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, ) works the same as .splitlines() Neither retain the EOL for each line, though. The only way I'm a

Re: how to split text into lines?

2008-07-30 Thread Miles
On Wed, Jul 30, 2008 at 4:45 PM, kj wrote: >>What's the Python idiom for splitting text into lines, preserving >>the end-of-line sequence in each line? > > > Sorry, I should have googled this first. I just found splitlines()... > > Still, for my own edification, is there a way to achieve the same

Re: how to split text into lines?

2008-07-30 Thread kj
In <[EMAIL PROTECTED]> kj <[EMAIL PROTECTED]> writes: >In Perl, one can break a chunk of text into an array of lines while >preserving the trailing line-termination sequence in each line, if >any, by splitting the text on the regular expression /^/: > DB<1> x split(/^/, "foo\nbar\nbaz") >0 'f

how to split text into lines?

2008-07-30 Thread kj
In Perl, one can break a chunk of text into an array of lines while preserving the trailing line-termination sequence in each line, if any, by splitting the text on the regular expression /^/: DB<1> x split(/^/, "foo\nbar\nbaz") 0 'foo ' 1 'bar ' 2 'baz' But nothing like this seems to work