the output in reference of descriptor.

luofeiyu elearn2014 at gmail.com
Sat Aug 23 23:23:28 EDT 2014


let me paste it again to make my question more clear:

     >>>c2.d
     __get__() is called <__main__.C2 object at 0x000000000297BE10> 
<class '__main__.C2'>
     <__main__.C object at 0x000000000297BBA8>

     >>> c2.d.a
     __get__() is called <__main__.C2 object at 0x000000000297BE10> 
<class '__main__.C2'>
     __getattribute__() is called
     'abc'

Why the result of c2.d.a  is not :

     __get__() is called <__main__.C2 object at 0x000000000297BE10> 
<class __main__.C2'>
     <__main__.C object at 0x000000000297BBA8>
     __getattribute__() is called
     'abc'

Why the` return self` in the __get__ method in class C  does not work? 
Why there is no <__main__.C object at 0x000000000297BBA8>  in the output?


and the source code are:


|class C(object):
     a = 'abc'
     def __getattribute__(self, *args, **kwargs):
         print("__getattribute__() is called")
         return object.__getattribute__(self, *args, **kwargs)
     def __getattr__(self, name):
         print("__getattr__() is called ")
         return name + " from getattr"
     def __get__(self, instance, owner):
         print("__get__() is called", instance, owner)
         return self
     def foo(self, x):
         print(x)


class C2(object):
     d = C()


|


On 8/23/2014 12:10 PM, Ian Kelly wrote:
> On Thu, Aug 21, 2014 at 7:25 PM, luofeiyu <elearn2014 at gmail.com 
> <mailto:elearn2014 at gmail.com>> wrote:
> > >>> c2.d.a
> > __get__() is called <__main__.C2 object at 0x000000000297BE10> 
> <class '__main__.
> > C2'>
> > __getattribute__() is called
> > 'abc'
> >
> > Why the result of c2.d.a  is not :
> >
> > __get__() is called <__main__.C2 object at 0x000000000297BE10> 
> <class '__main__.
> > C2'>
> > __getattribute__() is called
> > 'abc'
>
> As far as I can tell you pasted the same output twice, so I don't 
> understand what it is that you're asking.
>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140824/6a64fd92/attachment.html>


More information about the Python-list mailing list