newbie question: if var1 == var2:

rdmurray at bitdance.com rdmurray at bitdance.com
Thu Dec 11 18:24:44 CET 2008


On Thu, 11 Dec 2008 at 10:24, Kirk Strauser wrote:
> At 2008-11-29T04:02:11Z, Mel <mwilson at the-wire.com> writes:
>
>> You could try
>>
>> for item in fname:
>>     item = item.strip()
>
> This is one case where I really miss Perl's "chomp" function.  It removes a
> trailing newline and nothing else, so you don't have to worry about losing
> leading or trailing spaces if those are important to you.

     >>> '  ab c  \r\n'.rstrip('\r\n')
     '  ab c  '
     >>> '  ab c  \n'.rstrip('\r\n')
     '  ab c  '
     >>> '  ab c  '.rstrip('\r\n')
     '  ab c  '

--RDM



More information about the Python-list mailing list