Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76840
| X-Received | by 10.66.90.193 with SMTP id by1mr6232949pab.30.1408772653852; Fri, 22 Aug 2014 22:44:13 -0700 (PDT) |
|---|---|
| X-Received | by 10.50.117.7 with SMTP id ka7mr72068igb.2.1408772653751; Fri, 22 Aug 2014 22:44:13 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!r2no5354301igi.0!news-out.google.com!aw9ni2igc.0!nntp.google.com!r2no5354295igi.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Fri, 22 Aug 2014 22:44:13 -0700 (PDT) |
| In-Reply-To | <mailman.13266.1408670735.18130.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=123.192.37.172; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw |
| NNTP-Posting-Host | 123.192.37.172 |
| References | <mailman.13266.1408670735.18130.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <0b731225-3572-4357-aba5-2284dbaa2d65@googlegroups.com> (permalink) |
| Subject | Re: the output in reference of descriptor. |
| From | CHIN Dihedral <dihedral88888@gmail.com> |
| Injection-Date | Sat, 23 Aug 2014 05:44:13 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:76840 |
Show key headers only | View raw
On Friday, August 22, 2014 9:25:02 AM UTC+8, luofeiyu wrote:
> class C(object):
>
Well, in python class is treated
as onte of the first class built in
operations.
class "new_class_ame" ( parentclasses)
Please check this syntax first in Python.
> 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()
>
>
>
>
>
> >>> c2.d
>
> __get__() is called <__main__.C2 object at 0x000000000297BE10> <class
>
> '__main__.
>
> C2'>
>
> <__main__.C object at 0x000000000297BBA8>
>
>
>
> I understant the result ,c2.d trigger the __get__ method in class C.
>
> def __get__(self, instance, owner):
>
> print("__get__() is called", instance, owner)
>
> return self
>
>
>
> It print "__get__() is called", instance, owner and return self
>
> `<__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'>
>
> __getattribute__() is called
>
> 'abc'
>
>
>
> Why the` return self` in the __get__ method in class C does not work?
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
the output in reference of descriptor. luofeiyu <elearn2014@gmail.com> - 2014-08-22 09:25 +0800 Re: the output in reference of descriptor. CHIN Dihedral <dihedral88888@gmail.com> - 2014-08-22 22:44 -0700
csiph-web