Re: Add methods to string objects.
- From: "simon.dahlbacka@xxxxxxxxx" <simon.dahlbacka@xxxxxxxxx>
- Date: 30 Jun 2005 05:31:01 -0700
You can even get closer, but it is NOT recommended
class foostr(str):
def plural (self):
if self.value[-1] in "sz":
return self.value + "es"
else:
return self.value + "s"
#ugly hack
setattr(__builtins__, "str", foostr)
print str("apple").plural()
# this however does not work
# print "apple".plural()
.
- Follow-Ups:
- Re: Add methods to string objects.
- From: Roy Smith
- Re: Add methods to string objects.
- References:
- Add methods to string objects.
- From: Negroup
- Re: Add methods to string objects.
- From: Roy Smith
- Add methods to string objects.
- Prev by Date: Re: Store multiple dictionaries in a file
- Next by Date: Re: POP3 and "seen" flag
- Previous by thread: Re: Add methods to string objects.
- Next by thread: Re: Add methods to string objects.
- Index(es):