Stripping new lines from strings?
Joal Heagney
s713221 at student.gu.edu.au
Sun Aug 27 08:21:52 EDT 2000
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
More information about the Python-list
mailing list