MyClass and its instance are defined in myModule.py:
class MyClass(object):
pass
obj = MyClass()
Define function as obj's method:
from myModule import obj
def function(msg):
print msg
How to extend MyClass instance with function as method?
One way:
obj.function = function
But this won't be the same as if it would be defined in Class definition, e.g.:
class MyClass(object):
def __init__(self):
self.value = 'Value'
def function(self, msg):
print msg, self.value
After function is defined as MyClass method it can access the Class's attributes such as self.value.