What is the Python equivalent of Perl\'s chomp function, which removes the last character of a string if it is a newline?
chomp
This will work both for windows and linux (bit expensive with re sub if you are looking for only re solution)
import re if re.search("(\\r|)\\n$", line): line = re.sub("(\\r|)\\n$", "", line)