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


Groups > comp.lang.python > #31646

Re: Inheritance Question

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'jeff': 0.04; 'attribute': 0.05; 'attributes': 0.07; 'subject:Question': 0.07; 'instance.': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '"this': 0.13; '#this': 0.16; 'googling': 0.16; 'name"': 0.16; 'subclasses.': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'putting': 0.20; 'trying': 0.21; 'cc:2**0': 0.23; 'class.': 0.23; 'sets': 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; 'trouble': 0.28; 'skip:_ 10': 0.29; 'class': 0.29; 'maybe': 0.29; 'code': 0.31; 'gets': 0.32; 'print': 0.32; 'belong': 0.33; 'instances': 0.33; 'text,': 0.33; "can't": 0.34; 'list.': 0.35; 'but': 0.36; 'method': 0.36; 'itself': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'help': 0.40; 'your': 0.60; 'behavior': 0.64; 'header:Reply-To:1': 0.68; 'everybody': 0.69; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'received:74.208.4.194': 0.84
Date Thu, 18 Oct 2012 10:51:55 -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 Jeff Jeffries <jeff.jeffries.iii@gmail.com>
Subject Re: Inheritance Question
References <CANNB2xtaLMC49Y=xKoJn_7jNEJixzUsQZa019wZZw+d64cf3rg@mail.gmail.com>
In-Reply-To <CANNB2xtaLMC49Y=xKoJn_7jNEJixzUsQZa019wZZw+d64cf3rg@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:IFWXEC7W1w39YvL9nunKOGwAYsQNewUyXeT+rnVI2Sr T8LH5EBwhRZ/NL3gPVajhsKhz0Nyys8zEdWNxG0UFNx/gXbUY+ i4cRfhFqD8tQYzcC9ExD7yhLc3YBOgWF4gqBaRcq84FlgDiW0M grk5WGEgn/ubPaYeBApO51TaP9op/nx/4iU5AegCdNdYJ42bDC 1K9dRDf6VExF8UDbtLp0qrqDHSInwleL+23alAar/TuAAlhXfv qbYwWBTyIcOYr1y6xBKvuuHDKmuW9RSvMFNYy4qSKqoFDDNOLE zeKNhx+GCSLKIAd1dA9aLEpg549KvuBrwLEouHNwXvOHBl4Vg= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.2441.1350571938.27098.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350571938 news.xs4all.nl 6947 [2001:888:2000:d::a6]:44224
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31646

Show key headers only | View raw


On 10/18/2012 10:10 AM, Jeff Jeffries wrote:
> Hello everybody
>
> When I set "AttributeChanges" in my example, it sets the same value for all
> other subclasses. Can someone help me with what the name of this behavior
> is (mutable class global?) ? .... I don't know any keywords... having
> trouble googling it
>

I can't understand your code or what you're trying to do with it, but
maybe i can help anyway.  Incidentally, putting code in an attachment
will hide it from many users of this mailing list.  Just paste it inline
in your message, and make sure your message is composed as text, not html.


Attributes can be attached to the class or to the instance.  Those
attached to the class are shared among all instances that don't hide
them by having instance attributes of the same name.

Any attribute bound in an instance method is specific to that instance. 
Attributes bound in the class itself belong to the class.

class MyClass:
    classAttr1 = 42           #this is a class attribute
    classAttr2 = "will be masked"   #also this
    def __init__(self):
        self.instance_attr = "each instance gets its own"
        self.classAttr2 = "this makes an instance attribute of the same
name"

    def test(self):
        print self.classAttr1    #prints 42
        print self.classAttr2   #prints    this makes an ...
        print MyClass.classAttr2  #prints    will be masked

a = MyClass()
a.test()




-- 

DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Inheritance Question Dave Angel <d@davea.name> - 2012-10-18 10:51 -0400

csiph-web