Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31644 > unrolled thread
| Started by | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| First post | 2012-10-18 15:31 +0100 |
| Last post | 2012-10-18 15:31 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Inheritance Question Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-18 15:31 +0100
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2012-10-18 15:31 +0100 |
| Subject | Re: Inheritance Question |
| Message-ID | <mailman.2439.1350570697.27098.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web