Class Factories in Python: How?

Robin Dunn robin at alldunn.com
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
a
> 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 AllDunn.com
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!






More information about the Python-list mailing list