A question about inheritance
arserlom at gmail.com
arserlom at gmail.com
Sun May 8 16:01:58 EDT 2005
Thanks.
Jp Calderone wrote:
> On 8 May 2005 12:07:58 -0700, arserlom at gmail.com wrote:
> >Hello I have a question about inheritance in Python. I'd like to do
> >something like this:
> >
> > class cl1:
> > def __init__(self):
> > self.a = 1
> >
> > class cl2(cl1):
> > def __init__(self):
> > self.b = 2
> >
> >But in such a way that cl2 instances have atributes 'b' AND 'a'.
> >Obviously, this is not the way of doing it, because the __init__
> >definition in cl2 overrides cl1's __init__.
> >
> >Is there a 'pythonic' way of achieving this?
>
> class cl2(cl1):
> def __init__(self):
> cl1.__init__(self)
> self.b = 2
>
> Jp
More information about the Python-list
mailing list