getattr(foo, 'foobar') not the same as foo.foobar?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Mar 14 09:19:27 EDT 2008


Mel a écrit :
(snip)
> (What Diez said.)  From what I've seen, f.bar creates a bound method 
> object by taking the unbound method Foo.bar and binding its first 
> parameter with f. 

Nope. it's Foo.__dict__['bar'] (that is, the function bar defined in the 
namespace of class Foo) that creates a bound instancemethod object when 
looked up on a Foo instance - or an unbound instancemethod object when 
looked up on Foo. FWIW, types.UnboundMethodType and types.MethodType are 
both aliases to instancemethod type.





More information about the Python-list mailing list