Class variable inheritance

Steven D'Aprano steven at
Wed Sep 9 00:53:38 CEST 2009

On Tue, 08 Sep 2009 04:36:19 -0700, HPJ wrote:

>> Makes sense to me. To step through what's happening:
>> >>> A.n, B.n
>> (0, 0)
>> Here, the lookup on B.n fails (that is, B itself has no variable n),
>> and thus falls back to A.n
> See, this is what tripped me up, right at the beginning. I thought B
> would inherit (as in copy) the variable n from A.

Inherit does not mean copy. What makes you think it does? Given the 

class A(object):
    def foo(self):
        return "foo"

class B(A):

would you expect the B class to have a copy of the foo method?


More information about the Python-list mailing list