Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'value,': 0.03; 'interpreter': 0.04; 'output': 0.04; 'attribute': 0.05; 'class,': 0.07; 'attribute.': 0.09; 'fetch': 0.09; "object's": 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'a()': 0.16; 'a(object):': 0.16; 'instances,': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'subject:object': 0.16; 'wrote:': 0.17; 'documented': 0.17; 'instance': 0.17; 'instance,': 0.17; 'this:': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'am,': 0.27; 'cc:addr:gmail.com': 0.27; 'cc:2**2': 0.27; "doesn't": 0.28; 'behavior.': 0.29; 'class': 0.29; 'code': 0.31; 'print': 0.32; 'instances': 0.33; 'much.': 0.33; 'right?': 0.33; 'received:google.com': 0.34; 'same.': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'cc:no real name:2**1': 0.36; 'useful': 0.36; 'thank': 0.36; 'one,': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'your': 0.60; 'most': 0.61; 'first': 0.61; 'kind': 0.61; 'provide': 0.62; "'it": 0.84; 'received:209.85.216.184': 0.84 Newsgroups: comp.lang.python Date: Thu, 30 Aug 2012 05:57:32 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2001:250:6803:3307:8dfc:c7e7:1bea:5a8c; posting-account=ZQB0YgoAAADQhrIKjIYiYK-w-br65wWz References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 2001:250:6803:3307:8dfc:c7e7:1bea:5a8c MIME-Version: 1.0 Subject: Re: class object's attribute is also the instance's attribute? From: =?UTF-8?B?6ZmI5Lyf?= To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org, d@davea.name, =?UTF-8?B?6ZmI5Lyf?= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346331455 news.xs4all.nl 6975 [2001:888:2000:d::a6]:54191 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28115 =E5=9C=A8 2012=E5=B9=B48=E6=9C=8830=E6=97=A5=E6=98=9F=E6=9C=9F=E5=9B=9BUTC+= 8=E4=B8=8B=E5=8D=887=E6=97=B654=E5=88=8635=E7=A7=92=EF=BC=8CDave Angel=E5= =86=99=E9=81=93=EF=BC=9A > On 08/30/2012 06:55 AM, =E9=99=88=E4=BC=9F wrote: >=20 > > when i write code like this: >=20 > > >=20 > > class A(object): >=20 > > =20 >=20 > > d =3D 'it is a doc.' >=20 > > =20 >=20 > > >=20 > > t =3D A() >=20 > > >=20 > > print t.__class__.d >=20 > > print t.d >=20 > > >=20 > > the output is same. >=20 > > >=20 > > so it means class object's attribute is also the instance's attribute. = is it right? i can not understand it. >=20 >=20 >=20 > In your example, you have no instance attribute. So when you use the >=20 > syntax to fetch one, the interpreter looks first at the instance, >=20 > doesn't find it, then looks in the class, and does. That is documented >=20 > behavior. Some people use it to provide a kind of default value for >=20 > instances, which can be useful if most instances need the same value, >=20 > but a few want to overrride it. >=20 >=20 >=20 > --=20 >=20 >=20 >=20 > DaveA thank you very much.