perl chomp equivalent in python?

Hrvoje Niksic hniksic at iskon.hr
Thu Feb 10 03:25:34 EST 2000


François Pinard <pinard at iro.umontreal.ca> writes:

>   if line and line[-1] == '\n':
>       line = line[:-1]
> 
> You may remove the test for line if you know that it is not empty.

Or:

  if line[-1:] == '\n':
      line = line[:-1]

That works with both empty and non-empty lines.



More information about the Python-list mailing list