inheriting variables

Jp Calderone exarkun at intarweb.us
Thu Apr 17 09:33:16 EDT 2003


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?

  Jp

-- 
It is practically impossible to teach good programming style to
students that have had prior exposure to BASIC: as potential
programmers they are mentally mutilated beyond hope of
regeneration.        -- Dijkstra
-- 
 up 28 days, 9:02, 5 users, load average: 0.04, 0.03, 0.00





More information about the Python-list mailing list