Equivalent of Perl chomp?
Steve Holden
sholden at holdenweb.com
Thu Jan 31 09:07:37 EST 2002
"Paul Rubin" <phr-n2002a at nightsong.com> wrote...
> "Paul Watson" <pwatson at mail.com> writes:
> > Is chomp worth considering as an addition to the string functions?
>
> I think it should be added. I constantly find myself wanting it.
def chomp(s):
return s[:-1]
As long as you read text without binary mode, this is all you really need.
Plus it's short to write s[:-1] than chomp(s). Plus, if you find yourself
need chomp() all the time, maybe there's a more Pythonic solution to your
problems which your current Perlishness is causing you to overlook.
not-worth-adding-one-liners-ly y'rs - steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/
More information about the Python-list
mailing list