Add methods to string objects.

simon.dahlbacka at gmail.com simon.dahlbacka at gmail.com
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"
        else:
            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