Skip to content

Instantly share code, notes, and snippets.

@seungha-kim
Last active August 29, 2015 14:16
Show Gist options
  • Save seungha-kim/58fe1dd5b16a40dc62dd to your computer and use it in GitHub Desktop.
Save seungha-kim/58fe1dd5b16a40dc62dd to your computer and use it in GitHub Desktop.
Python metaclass example
# Shows the procedures of metaclass initializing (__init__, __prepare__)
# tested in Python 3.4
class MetaClass(type):
def __init__(self, name, bases, clsdict):
print('Class defined :')
print('mro', self.mro())
print('name', name)
print('bases', bases)
print('clsdict', clsdict)
super().__init__(name, bases, clsdict)
def __prepare__(self, *args, **kwargs):
print('preparing...')
return {}
class OrdinaryClass(object, metaclass=MetaClass):
print('evaluating class body...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment