On this python doc page it says:
Like its identity, an object’s type is also unchangeable.
And I try this script,
<
Old question but here's a technique for safely extending the type of a python object.
def extendObject(obj):
# Our extended type is explicitly derived from our existing type.
class Extended(obj.__class__):
# Whatever extensions you want to make.
def someMethod(self):
pass
# Change the type of the object.
obj.__class__ = Extended
return obj