Last active
August 29, 2015 14:16
-
-
Save seungha-kim/58fe1dd5b16a40dc62dd to your computer and use it in GitHub Desktop.
Python metaclass example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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