Add methods to string objects.

simon.dahlbacka at simon.dahlbacka at
Thu Jun 30 14:31:01 CEST 2005

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"
            return self.value + "s"

#ugly hack
setattr(__builtins__, "str", foostr)

print str("apple").plural()

# this however does not work
# print "apple".plural()

More information about the Python-list mailing list