What is the Python equivalent of Perl\'s chomp function, which removes the last character of a string if it is a newline?
chomp
You may use line = line.rstrip('\n'). This will strip all newlines from the end of the string, not just one.
line = line.rstrip('\n')