Re: Adding bound methods dynamically...
- From: Gregory Bond <gnb@xxxxxxxxxxx>
- Date: Wed, 31 Aug 2005 18:04:39 +1000
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 something interesting:
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): ... pass ... >>> type(foo) <type 'function'> >>> C.foo = foo >>> type(C.foo) <type 'instancemethod'> >>> c = C() >>> c.foo() foo called >>> type(c.foo) <type 'instancemethod'> >>>
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'.
.
- References:
- Adding bound methods dynamically...
- From: Kevin Little
- Adding bound methods dynamically...
- Prev by Date: Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- Next by Date: Re: Bicycle Repair Man usability
- Previous by thread: Re: Adding bound methods dynamically... CORRECTED
- Next by thread: ANN: M2Crypto 0.15
- Index(es):
Relevant Pages
|