How do I add my own custom attributes to existing built-in Python types? Like a string?

Posted by sfjedi on Stack Overflow See other posts from Stack Overflow or by sfjedi
Published on 2010-03-15T02:07:35Z Indexed on 2010/03/15 2:09 UTC
Read the original article Hit count: 331

I want to do something like this...

def helloWorld():
  print "Hello world!"
string.helloWorld = helloWorld
"foo".helloWorld()

Which would print out "Hello world!"

© Stack Overflow or respective owner

Related posts about python

Related posts about polymorphism