perl chomp equivalent in python?

Will Ware wware at world.std.com
Wed Feb 9 23:07:14 EST 2000


=?ISO-8859-1?Q?Fran=E7ois_Pinard?= (pinard at iro.umontreal.ca) wrote:
: To chop (even if line is truly empty):
:   line = line[:-1]
: To chomp:
:   if line and line[-1] == '\n':
:       line = line[:-1]

I often find myself doing things like this inside 'for ...readlines():'
loops, and it always strikes me as cheesy and inelegant. It'd be kinda
cool if readlines() could take an argument that meant to strip away
any trailing whitespace.
-- 
-- I can picture in my mind a world without war, a world without hate. And --
-- I can picture us attacking that world, because they'd never expect it.  --
Will Ware - N1IBT - wware at world.std.com



More information about the Python-list mailing list