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

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Mar 14 14:24:27 CET 2008


Erik Max Francis a écrit :
> Dave Kuhlman wrote:
> 
>> Basically, the above code is saying that foo.foobar is not the same as
>> getattr(foo, 'foobar').
> 
> Python promises that the behavior is the same.  It does not promise that 
> the _objects_ will be the same, which is what `is` determines.  That is, 
> you're not doing a useful test here.

FWIW, two methods are "the same" if they have identical (function, obj, 
cls) attributes. Looks like the equality test is correctly implemented:

 >>> foo.bar == foo.bar
True

HTH



More information about the Python-list mailing list