How to get rid the new line

Bengt Richter bokr at oz.net
Mon Jul 1 16:31:54 EDT 2002


On Sat, 29 Jun 2002 12:06:24 GMT, "Fredrik Lundh" <fredrik at pythonware.com> wrote:

>Peter Hansen wrote:
>
>> >  Could try this:
>> >
>> >         def chomp(line):
>> >                 if line[-1]=='\n':
>> >                         line=line[:-1]
>> >                 return line
>>
>> Just make sure you pass chomp() only lines that are not equal
>> to the empty string ''.
>
>or add the single character needed to make chomp a
>bit more robust:
>
>    def chomp(line):
>        if line[-1:] == '\n':
>            line = line[:-1]
>        return line
>

Better yet, why not a .stripEOL() method for strings?

Regards,
Bengt Richter



More information about the Python-list mailing list