Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Inheritance Question

Reply
Thread Tools

Re: Inheritance Question

 
 
Oscar Benjamin
Guest
Posts: n/a
 
      10-18-2012
On 18 October 2012 15:10, Jeff Jeffries <(E-Mail Removed)> 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.Attribu teDontChangeImmutable
print b.AttributeChanges,b.AttributeDontChange,b.Attribu teDontChangeImmutable

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

print a.AttributeChanges,a.AttributeDontChange,a.Attribu teDontChangeImmutable
print b.AttributeChanges,b.AttributeDontChange,b.Attribu teDontChangeImmutable
"""

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


Oscar
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Struct inheritance against class inheritance johnsonlau C++ 1 07-21-2008 04:58 PM
Interface inheritance vs Implementation inheritance. Daniel Pitts Java 27 02-27-2008 01:37 AM
Private Inheritance and Publice Inheritance karthikbalaguru C++ 9 09-10-2007 01:05 PM
mul. inheritance & overloading operator new/delete solved by virtual base inheritance? cppsks C++ 0 10-27-2004 07:49 PM
Private access modifier and Inheritance (Inheritance implementation in Java) maxw_cc Java 1 12-21-2003 11:38 AM



Advertisments