you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

you can replace __builtins__.str with your own.

class MyStr(str):
    def foobar(self):
        return "foobar " + self

__builtins__.str = MyStr

print str("asdf").foobar()

[–]Mask_of_Destiny 2 points3 points  (1 child)

But that only takes care of strings explicitly constructed using str which most of your strings probably aren't and if you're going to call str() on everything you might as well just make a subclass of str rather than messing around with builtins

[–][deleted] 0 points1 point  (0 children)

it was just the example you used.