Please note: this project is inactive since early 2006

3.1.2.2 Dynamic generation using metaclass

The second method makes use of the metaclass dynamic.CustomObjectMeta:

# file: Book.py
# We assume that the model is already loaded
from Modeling import dynamic

class Book:
  __metaclass__=dynamic.CustomObjectMeta
  entityName='Book'
  mdl_define_properties=1

  # your own code here

The metaclass CustomObjectMeta automatically adds all the necessary methods to a class for integration with the modeling framework. It looks for the following attributes in the class:

Last, then dynamic module also offers a method build_with_metaclass(model, define_properties=0, verbose=0) which you can use to derive the necessary package and modules from a model just like dynamic.build() we saw above, the ony difference being that the classes created at runtime use the metaclass approach.

Comments are welcome: Sebastien Bigaret / Modeling Home Page
Hosted by:SourceForge.net Logo