Stripping new lines from strings?

Matthew Schinckel matt at null.net
Tue Aug 22 10:47:17 EDT 2000


In message <31575A892FF6D1118F5800600846864D5B0FF2 at intrepid>, Simon Brunning
wrote:
> > From:	Richard Chamberlain [SMTP:richard_chamberlain at ntlworld.com]
> > Presuming you don't want any space at the end you can use string.strip
> > so...
> > 
> > import string
> > p="I line with a newline.\n"
> > q=string.rstrip(p)
> > 
> By default, string.split splits at whitespace, but it has an optional second
> argument, which allows you to split by any string. Wouldn't it be nice if
> string.strip and its siblings had a similar 2nd argument...

why not:

>>> string.join(string.split(str, '\n'))

Or would that be gloriously slow ?
-- 
Matthew Schinckel     <matt at null.net>




More information about the Python-list mailing list