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


Groups > comp.lang.python > #31644

Re: Inheritance Question

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
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; 'jeff': 0.04; '"""': 0.05; 'subject:Question': 0.07; 'python': 0.09; 'skip:b 70': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'languages.': 0.15; 'a()': 0.16; 'b()': 0.16; 'googling': 0.16; 'member"': 0.16; 'subclasses.': 0.16; 'wrote:': 0.17; 'equivalent': 0.20; 'received:74.125.82.174': 0.23; 'cc:2**0': 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; '[1]': 0.27; 'message-id:@mail.gmail.com': 0.27; 'trouble': 0.28; 'skip:_ 10': 0.29; 'class': 0.29; 'code': 0.31; 'print': 0.32; 'received:74.125.82': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'skip:a 70': 0.35; 'received:74.125': 0.36; 'october': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'help': 0.40; 'skip:a 30': 0.60; 'behavior': 0.64; 'here': 0.65; 'everybody': 0.69; 'oscar': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=P2ON42TrmkrVY4VdmLYGu9BHQY/YYBBIZp75dPf2nGo=; b=ZvNTEPf9nf6Nx/MN0ZKYMXe7+Ti/DnuDJ26JDxC/QZhyVt9iT7dJIVkAXap9Io3B7k 4vP3Qsos32kJswKViIHFSH1wFd2DRWBnyBKLQkuXA/8PP1Orpdn7AwhpzKsa8QsdCCrP VCf6qzK5j/J8YJAB+ydkY7cDhqgZ+dSAWcbfF73xRdMwPuKpw9qG4LtiqGU4z8vcMKmq qrmuDgsF9HfvsyXgWBFZ9IrbhA4MvDjExIye418ySF2iA1g+VVXcqo+JHfy3zrQKjSwk wIE1Tr2batzxZzWpBRkIzQn180w8/FiVHe7SPYm6K0NvRMf6U9NK/9vO/GKGCVSpX0qM SBXQ==
MIME-Version 1.0
In-Reply-To <CANNB2xtaLMC49Y=xKoJn_7jNEJixzUsQZa019wZZw+d64cf3rg@mail.gmail.com>
References <CANNB2xtaLMC49Y=xKoJn_7jNEJixzUsQZa019wZZw+d64cf3rg@mail.gmail.com>
Date Thu, 18 Oct 2012 15:31:36 +0100
Subject Re: Inheritance Question
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
To Jeff Jeffries <jeff.jeffries.iii@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.2439.1350570697.27098.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350570697 news.xs4all.nl 6938 [2001:888:2000:d::a6]:35831
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31644

Show key headers only | View raw


On 18 October 2012 15:10, Jeff Jeffries <jeff.jeffries.iii@gmail.com> 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
>
> Thanks in advance,

The code you attached is not so big that it can't just go in the
email. Here it is:

"""
class ABMixin:
    AttributeChanges = [1]
    AttributeDontChangeImmutable = 1
    def __init__(self):
        self.AttributeDontChange = [1]

class A(object,ABMixin):
    def __init__(self):
        ABMixin.__init__(self)

class B(object,ABMixin):
    def __init__(self):
        ABMixin.__init__(self)

a = A()
b = B()

print a.AttributeChanges,a.AttributeDontChange,a.AttributeDontChangeImmutable
print b.AttributeChanges,b.AttributeDontChange,b.AttributeDontChangeImmutable

a.AttributeChanges[0] = 2
a.AttributeDontChange[0] = 2
a.AttributeDontChangeImmutable = 2

print a.AttributeChanges,a.AttributeDontChange,a.AttributeDontChangeImmutable
print b.AttributeChanges,b.AttributeDontChange,b.AttributeDontChangeImmutable
"""

AttributeChanges is a "class attribute". This is the Python equivalent
of what would be a "static class member" in some other languages.


Oscar

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


Thread

Re: Inheritance Question Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-18 15:31 +0100

csiph-web