perl chomp equivalent in python?

François Pinard pinard at
Wed Feb 9 23:43:15 CET 2000

"a.c.a. serier" <a.serier at> writes:

> Perl has chomp() to do this.

To chop (even if line is truly empty):

  line = line[:-1]

To chomp:

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

You may remove the test for line if you know that it is not empty.

François Pinard

More information about the Python-list mailing list