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.