Class Factories in Python: How?

Warren Postma embed at
Mon May 1 21:52:36 CEST 2000

> If this is the main problem, there may be a way around it.  Could you do
> something like this:
> def marshalstruct_factory(newattributes):
>     class newclass(marshalstruct):
>          pass
>     newclass.attributes = newattributes
>     newclass.lookups = binstruct_lookup(attributes)
>     newclass.fieldcount = len(attributes)
>     return newclass

Wow that works! Thanks!

All this comes of course from the fact that Classes are first-class Objects
in python. Isn't that COOL?!

This, and the 'metaclasses' stuff definitely makes my head hurt, yet it's
somehow beautiful also.


More information about the Python-list mailing list