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

sashang at gmail.com sashang at gmail.com
Thu Jun 22 19:24:29 EDT 2006


Hi

I'd like to use metaclasses to dynamically generate a class based on a
parameter to the objects init function.

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

class Thing:
    __metaclass__ = MetaThing
    def __init__(self, extra_information):
         #Somehow pass extra_information to the MetaThing

extra_information = 1
t = Thing(extra_information)

The above sample won't work but I hope it demonstrates what I'm trying
to do.




More information about the Python-list mailing list