|
|
|
|
|
by storborg
5298 days ago
|
|
Use types.MethodType for that: >>> import types
>>>
>>> def hello(self):
... print self.name
...
>>> class Foo(object):
... name = 'blah'
...
>>> goo = Foo()
>>> goo.hi = types.MethodType(hello, Foo)
>>>
>>> goo.hi()
blah
Edit: pre-2.6 you'd use "new.instancemethod()" |
|