Skip to content

Instantly share code, notes, and snippets.

@disconnect3d
Created February 4, 2016 19:54
Show Gist options
  • Save disconnect3d/e720eea239d8b7488cb1 to your computer and use it in GitHub Desktop.
Save disconnect3d/e720eea239d8b7488cb1 to your computer and use it in GitHub Desktop.
Python tricky name mangling
class A:
def __a(self):
print("__a")
def _A__a(self):
print("_A__a")
def c(self):
self.__a()
self._A__a()
class B:
def _B__b(self):
print("_B__b")
def __b(self):
print("__b")
def c(self):
self.__b()
self._B__b()
a=A()
a.c()
a._A__a()
b=B()
b.c()
b._B__b()
# Output:
#_A__a
#_A__a
#_A__a
#__b
#__b
#__b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment