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


Groups > comp.lang.python > #28123

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'attribute': 0.05; 'attributes': 0.07; 'attribute.': 0.09; 'instances.': 0.09; 'cc:addr:python-list': 0.10; 'assume': 0.11; 'attributes.': 0.16; 'instances,': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'subject:object': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'visible': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'programming': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'am,': 0.27; 'probably': 0.29; 'class': 0.29; 'thursday,': 0.30; 'not.': 0.32; 'getting': 0.33; 'done': 0.34; 'subject:?': 0.35; 'except': 0.36; 'but': 0.36; 'test': 0.36; 'quite': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'shows': 0.38; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'think': 0.40; 'first': 0.61; '30,': 0.62; 'show': 0.63; 'learned': 0.65; 'august': 0.66; 'header:Reply-To:1': 0.68; 'today.': 0.69; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; '10:11': 0.84
Date Thu, 30 Aug 2012 10:30:35 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version 1.0
To Marco Nawijn <nawijn@gmail.com>
Subject Re: class object's attribute is also the instance's attribute?
References <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <e8b14404-2340-4743-b66b-e9afb701e676@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com>
In-Reply-To <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:VPKRVsbt6Ipc9futU5WboL37LVn5+y9F8l9hku8X3T5 dHSQ6S7iKC5Htqj17MqFY2ui7jUhg/+GcrQCMu72zm1Ap98Xjj 3EeZX07FtVoqSmhtSR9u442wMta4RhOs4XfIpud0JNA5XH+6aO 93U91so8afs/6owrlVTlECZ6tdmaEJ+Po8mWwh2VqJaswfMtlb o8HL+mhqhj6w+OuR5dKJsA4qdy/X18ojLOd0LWIGImnOsWZ7Jn lNXJTlWnNANw+Be5phwXZBQQQTBXTbMFxd1vr38vqayogOTFrO LUsEklOSMiiZ0oPYDQVY01ktyd96xASdfcOh/GzZbYEUEtpiQ= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
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>
Newsgroups comp.lang.python
Message-ID <mailman.3972.1346337059.4697.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1346337059 news.xs4all.nl 6944 [2001:888:2000:d::a6]:47522
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28123

Show key headers only | View raw


On 08/30/2012 10:11 AM, Marco Nawijn wrote:
> On Thursday, August 30, 2012 3:25:52 PM UTC+2, Hans Mulder wrote:
>> <snip>
>>
> Learned my lesson today. Don't assume you know something. Test it first ;). I have done quite some programming in Python, but did not know that class attributes are still local to the instances. 

They're not.  They're just visible to the instances, except where the
instance has an instance attribute of the same name.  Don't be confused
by dir(), which shows both instance and class attributes.

Please show me an example where you think you observe each instance
getting a copy of the class attribute.  There's probably some other
explanation.




-- 

DaveA

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