What is the Python equivalent of Perl\'s chomp function, which removes the last character of a string if it is a newline?
chomp
Just use :
line = line.rstrip("\n")
or
line = line.strip("\n")
You don't need any of this complicated stuff