Using metaclassed to dynamically generate a class based on a parameter to the objects init function.

Carl Banks invalidemail at aerojockey.com
Fri Jun 23 10:13:33 EDT 2006


sashang at gmail.com wrote:
> The extra_information is used in MetaThing to tell it what attributes
> to add to the class. For example:
>
> class MetaThing(type):
>      def __init__(cls, name, bases, dict, extra_information):
>          super(MetaThing, cls).__init__(name, bases, dict)
>          #setup the class based on the parameter extra_information
>          setattr(cls, make_name(extra_information),
> make_object(extra_information))
>
> Does that clarify things?

Why do the extra attributes need to be part of the class?  ISTM each
instance has its own class; therefore there it doesn't matter whether a
member is a class member or an instance member.


Carl Banks




More information about the Python-list mailing list