
Guido van Rossum wrote:
Someone just posted a patch to implement s.chomp() as a string method:
http://sourceforge.net/patch/?func=detailpatch&patch_id=103029&group_id=5470
Pseudo code (for those not aware of the Perl function by that name):
def chomp(s): if s[-2:] == '\r\n': return s[:-2] if s[-1:] == '\r' or s[-1:] == '\n': return s[:-1] return s
I.e. it removes a trailing \r\n, \r, or \n.
Any comments? Is this needed given that we have s.rstrip() already?
We already have .splitlines() which does the above (remove line breaks) not only for a single line, but for many lines at once. Even better: .splitlines() also does the right thing for Unicode. -- Marc-Andre Lemburg ______________________________________________________________________ Company: http://www.egenix.com/ Consulting: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/