Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28114

Re: class object's attribute is also the instance's attribute?

Received by 10.68.232.1 with SMTP id tk1mr987651pbc.7.1346331452750; Thu, 30 Aug 2012 05:57:32 -0700 (PDT)
Received by 10.68.233.5 with SMTP id ts5mr909833pbc.20.1346331452734; Thu, 30 Aug 2012 05:57:32 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!4no28334909pbn.1!news-out.google.com!a8ni100059889pbd.1!nntp.google.com!4no28334907pbn.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
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
NNTP-Posting-Host 2001:250:6803:3307:8dfc:c7e7:1bea:5a8c
References <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <mailman.3963.1346327629.4697.python-list@python.org>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <d439b45a-ff41-4552-8a81-a267aa984516@googlegroups.com> (permalink)
Subject Re: class object's attribute is also the instance's attribute?
From 陈伟 <chenwei.address@gmail.com>
Cc 陈伟 <chenwei.address@gmail.com>, python-list@python.org, d@davea.name
Injection-Date Thu, 30 Aug 2012 12:57:32 +0000
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:28114

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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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