Class Factories in Python: How?

Robin Dunn robin at
Mon May 1 17:56:00 EDT 2000

> Each type I want to create a new binary structure, I subclass it, but the
> subclassing procedures are getting complex because there are so many
> class-variables that need to be initialized.  So I decided to try to build
> class factory, like this:

Another approach is to use the "new" module.  You can create a new class
object by calling  new.classobj passing the class name, a tuple of base
classes, and a dictionary of class attributes.  This works great when the
base classes might be different each time.

Robin Dunn
Software Craftsman
robin at  Check it out!

More information about the Python-list mailing list