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

castironpi at gmail.com castironpi at gmail.com
Thu Mar 13 19:45:31 EDT 2008


> > Basically, the above code is saying that foo.foobar is not the same as
> > getattr(foo, 'foobar').
>
> > What gives?  This breaks my understanding of id(), the is operator, and
> > getattr().
>
> 4.  Both points above follow from the fact that foo.bar is really a
> function call that returns a (potentially) new object: in fact what
> really happens is something like
>
>     Foo.__dict__['bar'].__get__(foo, Foo).
>
> So every time foo.bar is executed an object is (or may be) created,
> with a new id.

When is it?  Why is the 'owner' argument there?  Do you ever use
'__set__'?



More information about the Python-list mailing list