Class Factories in Python: How?
Warren Postma
embed at geocities.com
Mon May 1 15:52:36 EDT 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.
Warren
More information about the Python-list
mailing list