Metaclass is like a black magic in python.
I wouldn't learn it if not necessary to read someone's code.
SqlObject uses it. So, if I want to port it to pys60 Dbms,
I need to learn metaclass.
Fortunately, this one is not too much to understand.
def __new__(meta, class_name, bases, new_attrs):
cls = type.__new__(meta, class_name, bases, new_attrs)
cls.__classinit__ = staticmethod(cls.__classinit__.im_func)
When you use it you do this
__metaclass__ = DeclarativeMeta
# ... and other class variables
def __classinit__(cls, new_attrs):
# do whatever you want with the new class
# do whatever you want with the new instance
You use this when you want a subclass to have some magic
done to it when it is first defined. What you say in
__classinit__ will get done to the new subclass, eg.
create more methods, properties, etc.