[Tutor] Extract lines from a multinile string
john at fouhy.net
Wed Oct 10 06:37:27 CEST 2007
On 10/10/2007, Eli Brosh <ebrosh at nana10.co.il> wrote:
> I have a multiline string such as:
> s='''This is the first line
> This is the second line
> This is the third longer line'''
> Note that s has no control character such as \n.
Did you check that?
>>> s = '''This is the first line.
... This is the second line.
... This is the third longer line.'''
>>> print s
This is the first line.
This is the second line.
This is the third londer line.
>>> print repr(s)
'This is the first line.\nThis is the second line.\nThis is the third
A multiline string has newline characters by definition. You can
split the string around them by using s.split():
['This is the first line.', 'This is the second line.', 'This is the
third longer line.']
More information about the Tutor