Stripping new lines from strings?

Tony Johnson gjohnson at gs.verio.net
Sun Aug 27 15:12:34 EDT 2000


Doesn't string.strip(string) do this???

Joal Heagney wrote:
> 
> thehaas at my-deja.com wrote:
> 
> > In article <31575A892FF6D1118F5800600846864D5B105A at intrepid>,
> >   Simon Brunning <SBrunning at trisystems.co.uk> wrote:
> > > > From:    Matthew Schinckel [SMTP:matt at null.net]
> > > > What about using re:
> > > >
> > > > re.sub("\n$", '', str)
> > > >
> >
> > Oh please, let's not make things complicated . . .
> >
> > str = str[:-1]
> >
> > Although you have to be sure that the last char is a \n, because it will
> > take off whatever the last char is.  Sorta like chop(str) in Perl.
> 
> Okay, easily fixed, *grins*
> 
> if str[-1] == '\n':
>     str = str[:-1]
> 
> JoalHeagney/AncientHart
> 
> --
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list