Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28115
| 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 | <chenwei.address@gmail.com> |
| 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 | <mailman.3963.1346327629.4697.python-list@python.org> |
| 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> <mailman.3963.1346327629.4697.python-list@python.org> |
| 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 | 陈伟 <chenwei.address@gmail.com> |
| 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, 陈伟 <chenwei.address@gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.3968.1346331455.4697.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
在 2012年8月30日星期四UTC+8下午7时54分35秒,Dave Angel写道: > On 08/30/2012 06:55 AM, 陈伟 wrote: > > > when i write code like this: > > > > > > class A(object): > > > > > > d = 'it is a doc.' > > > > > > > > > t = A() > > > > > > print t.__class__.d > > > print t.d > > > > > > the output is same. > > > > > > so it means class object's attribute is also the instance's attribute. is it right? i can not understand it. > > > > In your example, you have no instance attribute. So when you use the > > syntax to fetch one, the interpreter looks first at the instance, > > doesn't find it, then looks in the class, and does. That is documented > > behavior. Some people use it to provide a kind of default value for > > instances, which can be useful if most instances need the same value, > > but a few want to overrride it. > > > > -- > > > > DaveA thank you very much.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
class object's attribute is also the instance's attribute? 陈伟 <chenwei.address@gmail.com> - 2012-08-30 03:55 -0700
Re: class object's attribute is also the instance's attribute? Dave Angel <d@davea.name> - 2012-08-30 07:53 -0400
Re: class object's attribute is also the instance's attribute? 陈伟 <chenwei.address@gmail.com> - 2012-08-30 05:57 -0700
Re: class object's attribute is also the instance's attribute? 陈伟 <chenwei.address@gmail.com> - 2012-08-30 05:57 -0700
Re: class object's attribute is also the instance's attribute? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-08-30 13:22 +0200
Re: class object's attribute is also the instance's attribute? Marco Nawijn <nawijn@gmail.com> - 2012-08-30 05:34 -0700
Re: class object's attribute is also the instance's attribute? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-08-30 13:52 +0100
Re: class object's attribute is also the instance's attribute? Hans Mulder <hansmu@xs4all.nl> - 2012-08-30 15:25 +0200
Re: class object's attribute is also the instance's attribute? Marco Nawijn <nawijn@gmail.com> - 2012-08-30 07:11 -0700
Re: class object's attribute is also the instance's attribute? Dave Angel <d@davea.name> - 2012-08-30 10:30 -0400
Re: class object's attribute is also the instance's attribute? Marco Nawijn <nawijn@gmail.com> - 2012-08-30 07:48 -0700
Re: class object's attribute is also the instance's attribute? Dave Angel <d@davea.name> - 2012-08-30 11:18 -0400
Re: class object's attribute is also the instance's attribute? Marco Nawijn <nawijn@gmail.com> - 2012-08-30 07:48 -0700
Re: class object's attribute is also the instance's attribute? Hans Mulder <hansmu@xs4all.nl> - 2012-08-30 17:20 +0200
Re: class object's attribute is also the instance's attribute? Ben Finney <ben+python@benfinney.id.au> - 2012-08-31 09:58 +1000
csiph-web