Adding bound methods dynamically...
gnb at itga.com.au
Wed Aug 31 10:04:39 CEST 2005
Kevin Little wrote:
> I want to dynamically add or replace bound methods in a class. I want
I asked a seemingly-unrelated question a week or so ago, and learned
Python 2.3.4 (#2, Jul 12 2004, 12:46:36)
[GCC 3.3] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(self):
.. print "foo called"
>>> class C(object):
>>> C.foo = foo
>>> c = C()
I.e. assigning a normal function object to a class object turns it into
a member function!
You can read more in the thread with the subject 'keeping a ref to a
non-member function in a class'.
More information about the Python-list