inheriting variables
Steve Holden
sholden at holdenweb.com
Thu Apr 17 11:04:55 EDT 2003
"Jp Calderone" <exarkun at intarweb.us> wrote ...
> On Thu, Apr 17, 2003 at 10:34:08AM +0000, Haran Shivanan wrote:
> > This seems like a fairly straight forward thing but I'm not sure about
how
> > to implement it.
> > I have a base class from which I'm deriving several new classes:
> > class A:
> > mem_a=0
> > mem_b=1
> > class B(A):pass
> >
> > I want B to inherit mem_a and mem_b from A without my having to explicit
do
> > something like:
> >
> > self.mem_a = 0
> >
> > in the constructor for class B.
>
> class A:
> a = 0
> b = 1
>
> class B(A):
> pass
>
> b = B()
> print b.a, b.b
>
> Isn't this the behavior you desire? If not, could you clarify your
> question?
Probably not.
>>> class A:
... a = 0
... b = 1
...
>>> class B(A):
... pass
...
>>> b = B()
>>> A.a = 23
>>> b.a
23
>>>
I suspect the OP wants a separate class variable for each subclass. Right,
Haran?
regards
--
Steve Holden http://www.holdenweb.com/
How lucky am I? http://www.google.com/search?q=Steve+Holden&btnI=1
Python Web Programming http://pydish.holdenweb.com/pwp/
More information about the Python-list
mailing list