What is the Python equivalent of Perl\'s chomp function, which removes the last character of a string if it is a newline?
chomp
And I would say the "pythonic" way to get lines without trailing newline characters is splitlines().
>>> text = "line 1\nline 2\r\nline 3\nline 4" >>> text.splitlines() ['line 1', 'line 2', 'line 3', 'line 4']