Posts

Showing posts from September, 2017

Python: metaclass

From:  https://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python Also:   http://jfine-python-classes.readthedocs.io/en/latest/metaclass-attribute.html             https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/ Classes as objects Before understanding metaclasses, you need to master classes in Python. And Python has a very peculiar idea of what classes are, borrowed from the Smalltalk language. In most languages, classes are just pieces of code that describe how to produce an object. That's kinda true in Python too: >>> class ObjectCreator ( object ): ... pass ... >>> my_object = ObjectCreator () >>> print ( my_object ) < __main__ . ObjectCreator object at 0x8974f2c > But classes are more than that in Python. Classes are objects too. Yes, objects. As soon as you use the keyword  class , Python executes it and creates an OBJECT. The instruct...