Skip to content

Instantly share code, notes, and snippets.

@IuryAlves IuryAlves/
Last active Dec 11, 2016

What would you like to do?
Simple example to explain name mangling in python.
# coding: utf-8
class Image(object):
def __format(self):
return 'PNG'
image = Image()
image.__format() # will raise AttributeError
except AttributeError as exc:
print(dir(image)) # but the format method exists with another name
format_ = getattr(image, '_Image__format')()
print(format_) # PNG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.