class A(object): def __get(self): pass def _m(self): return self.__get() class B(A): def _m(self): return str(self.__get()) print(A()._m()) print(B()._m())
Why print(A()._m()) print None , but print(B()._m()) raises AttributeError: 'B' object has no attribute '_B__get' ?
I thought double underscore prevents method overriding.
UPDATE
You write that __get is private.
Then why does the following work?
class A(object): def __get(self): pass def _m(self): return self.__get() class B(A): pass print(A()._m()) print(B()._m())
Why doesn't this code raise an AttributeError and print None twice?
python
Andrew Fount
source share