Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76921
| Date | 2014-08-24 11:23 +0800 |
|---|---|
| From | luofeiyu <elearn2014@gmail.com> |
| Subject | Re: the output in reference of descriptor. |
| References | <53F69BEE.5000000@gmail.com> <CALwzidmGMn2oPm91PbL-P2_=v2G+ijrWaisZRY-k_KnwS91VoQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13371.1408850628.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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@gmail.com
> <mailto:elearn2014@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.
>
>
>
>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: the output in reference of descriptor. luofeiyu <elearn2014@gmail.com> - 2014-08-24 11:23 +0800 Re: the output in reference of descriptor. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-24 17:18 +1000
csiph-web