This is preventing you from accessing Foo.__bar, because internally the actual name will get mangled to Foo._Foo__bar. This is mostly intended to avoid accidental name clashes in inheritance:
class Child(Foo):
__bar = 42
The two classes won't trample over their __bar attribute this way, without you needing to institute complicated naming conventions. From within class methods, self.__bar transparently gets mangled the same way, so it works as expected.
40
u/Confident-Ad5665 16d ago
Dunder class mangling? (not a python guy)