perl chomp equivalent in python?

François Pinard pinard at iro.umontreal.ca
Wed Feb 9 23:43:15 CET 2000


"a.c.a. serier" <a.serier at hccnet.nl> 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   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list