Skip to content Skip to sidebar Skip to footer

Name Mangling In Python

Consider the following program. class A(): class __B(): def __c(self): pass a = A() dir(a) ['_A__B', '__doc__', '__module__'] dir(a._A__B) ['_B__c', '__

Solution 1:

It's right there in the docs (emphasis added):

Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with leading underscore(s) stripped

Post a Comment for "Name Mangling In Python"