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? --Guido van Rossum (home page: http://www.python.org/~guido/)
On Thu, 28 Dec 2000 10:04:23 -0500, Guido <guido@digicool.com> wrote:
Someone just posted a patch to implement s.chomp() as a string method: ... Any comments? Is this needed given that we have s.rstrip() already?
I've always considered this a different operation from rstrip(). When you intend to be as surgical in your changes as possible, it is important *not* to use rstrip(). I don't feel strongly that it needs to be implemented in C, though I imagine people who do a lot of string processing feel otherwise. It's just hard to beat the performance difference if you are doing this a lot. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> PythonLabs at Digital Creations
On Thu, 28 Dec 2000, Guido van Rossum <guido@digicool.com> wrote:
Someone just posted a patch to implement s.chomp() as a string method: ... Any comments? Is this needed given that we have s.rstrip() already?
Yes. i=0 for line in fileinput.input(): print '%d: %s' % (i, line.chomp()) i++ I want that operation to be invertable by sed 's/^[0-9]*: //'
Guido van Rossum writes:
Someone just posted a patch to implement s.chomp() as a string method: I.e. it removes a trailing \r\n, \r, or \n.
Any comments? Is this needed given that we have s.rstrip() already?
-1 from me. P=NP (Python is not Perl). "Chomp" is an excessively cute name. And like you said, this is too much like "rstrip" to merit a separate method.
-1 from me. P=NP (Python is not Perl). "Chomp" is an excessively cute name. And like you said, this is too much like "rstrip" to merit a separate method.
My thoughts exactly. I can't remember _ever_ wanting to chomp() when rstrip() wasnt perfectly suitable. I'm sure it happens, but not often enough to introduce an ambiguous new function purely for "feature parity" with Perl. Mark.
Charles G Waldman writes: | | P=NP (Python is not Perl) Is it too late to suggest this for the SPAM9 t-shirt? :)
Charles G Waldman writes: | | P=NP (Python is not Perl)
Is it too late to suggest this for the SPAM9 t-shirt? :)
By just about a day -- I haven't seen the new design yet, but Just & Eric were supposed to design it today and hand in the final proofs tomorrow. I believe the slogan will be "it fits your brain" (or "it fits my brain"). But if you print a bunch of P=NP shirts, I'm sure you can sell them with a profit, both in Long Beach and in San Diego (at the O'Reilly Open Source conference)... --Guido van Rossum (home page: http://www.python.org/~guido/)
On Sun, 14 Jan 2001 21:24:36 -0500, Guido van Rossum <guido@python.org> wrote:
But if you print a bunch of P=NP shirts, I'm sure you can sell them with a profit, both in Long Beach and in San Diego (at the O'Reilly Open Source conference)...
And the Libre Software Meeting (http://lsm.abul.org), which has a Python subtopic too. (Since it's in France, no one is calling it "free", so it's probable you can sell those T-shirts there...) -- Moshe Zadka <sig@zadka.site.co.il> This is a signature anti-virus. Please stop the spread of signature viruses!
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/
On Thu, 28 Dec 2000, "M.-A. Lemburg" <mal@lemburg.com> wrote: [about chomp]
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.
OK, I retract my earlier +1, and instead I move that this be added to the FAQ. Where is the FAQ maintained nowadays? The grail link doesn't work anymore. -- Moshe Zadka <sig@zadka.site.co.il> This is a signature anti-virus. Please stop the spread of signature viruses!
participants (8)
-
Captain Senorita
-
Charles G Waldman
-
Fred L. Drake
-
Guido van Rossum
-
Guido van Rossum
-
M.-A. Lemburg
-
Mark Hammond
-
Moshe Zadka