This is almost too trivial, but perhaps it will be useful to perl fugitives searching for a pythonic way to remove line endings from strings.
The answer: use rstrip()
Python, 7 lines
1 2 3 4 5 6 7
# single-liners using rstrip() strvar = strvar.rstrip() strlist = [l.strip for l in strlist] filelines = [l.rstrip() for l in open(filename)]
Not quite the same as chomp. 'chomp' removes the newline only. An equivalent call would be:
A bare 'rstrip' removes all whitespace from the end.