Dynamically adding and removing methods
Terry Reedy
tjreedy at udel.edu
Wed Sep 28 16:31:31 EDT 2005
"Ron Adam" <rrr at ronadam.com> wrote in message
news:sXA_e.112986$xl6.67455 at tornado.tampabay.rr.com...
> Actually I think I'm getting more confused. At some point the function
> is wrapped. Is it when it's assigned, referenced, or called?
When it is referenced via the class.
If you lookup in class.__dict__, the function is still a function.
>>> class C(object):
... def meth(self): pass
...
>>> C.__dict__['meth']
<function meth at 0x0090B018>
>>> C.meth
<unbound method C.meth>
>>> C().meth
<bound method C.meth of <__main__.C object at 0x008E4688>>
I am not sure, without looking, how much of this is language definition and
how much CPython implementation, but I think mostly the latter, as long as
the inheritance tree lookup behavior is as specified.
Terry J. Reedy
More information about the Python-list
mailing list