Skip to content

Instantly share code, notes, and snippets.

@cocoatomo
Created December 7, 2010 11:38
Show Gist options
  • Save cocoatomo/731698 to your computer and use it in GitHub Desktop.
Save cocoatomo/731698 to your computer and use it in GitHub Desktop.
Python での name mangling の上書き動作
class SecretFirst(object):
def __secret(self):
print('__secret')
def _SecretFirst__secret(self):
print('_SecretFirst__secret')
class SecretSecond(object):
def _SecretSecond__secret(self):
print('_SecretSecond__secret')
def __secret(self):
print('__secret')
if __name__ == '__main__':
sf = SecretFirst()
print(dir(sf))
sf._SecretFirst__secret() # -> _SecretFirst__secret
ss = SecretSecond()
print(dir(ss))
ss._SecretSecond__secret() # -> __secret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment