newbie question: if var1 == var2:

J. Cliff Dyer jcd at sdf.lonestar.org
Fri Dec 12 16:35:11 CET 2008


On Thu, 2008-12-11 at 13:44 -0600, Kirk Strauser wrote:
> At 2008-12-11T17:24:44Z, rdmurray at bitdance.com writes:
> 
> >     >>> '  ab c  \r\n'.rstrip('\r\n')
> >     '  ab c  '
> >     >>> '  ab c  \n'.rstrip('\r\n')
> >     '  ab c  '
> >     >>> '  ab c  '.rstrip('\r\n')
> >     '  ab c  '
> 
> I didn't say it couldn't be done.  I just like the Perl version better.

Python has a version equally good:

def chomp(s):
    return s.rstrip('\r\n')

chomp("foo\n")
chomp("foo")
chomp("perl\r\n")

You'll hardly miss Perl at all. ;)




More information about the Python-list mailing list