Daily Reading List -2011-05-11
This is the collection that I read today when browsing the internet.
# About the metaclass in Python
metaclass — acts as a template for producing classes, a factory of classes
Some points need to be clarify:
a) To have a new-style class
use __metaclass__ = type
is equivalent to subclass the build-in class object
If you define your own metaclass, then all the classes that are defined in the scope of this metaclass will automatically be the subclass of this metaclass.
b) Use method resolution order to check the order of the superclass
c) The instance of the metaclass is a class. Thus, the attributes of the metaclass is only available for the generated-class (by metaclass), but not for the instance of the generated-class
d) One of the adavantage of using metaclass is that the behaviors of the class may not be directly written as code(not directly defined), but are instead created by calling functions at runtime( if it is necessary, that function will be called), with dynamic arguments.
oop – What is a metaclass in Python? – Stack Overflow
Guide to Python introspection
Metaclass programming in Python
Charming Python: Create declarative mini-languages
A Primer on Python Metaclass Programming – O’Reilly Media
Just a little Python: Stupid Metaclass and Template Tricks
Unifying types and classes in Python 2.2