perl chomp equivalent in python?

Hrvoje Niksic hniksic at iskon.hr
Thu Feb 10 09:25:34 CET 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