How to define a class that can create instances of computed type/class?

Michele Simionato mis6 at pitt.edu
Sun Dec 15 16:07:26 EST 2002


Pierre Rouleau <prouleau_nospam at impathnetworks.com> wrote in message news:<3DFA7C92.6040406 at impathnetworks.com>...
> Ian Bicking wrote:
> 
> >
> > 
> > You could also use new-style classes with a meta-class or with the
> > __new__ method.  But I don't think you'll find them functionally
> > different from the code you have now and it won't be worth the effort.
> >
> 
> Is meta-class functionality robust? 

I am trying to discover it.

> Has it been used heavility ?

It is relatively new and probably not well known to everybody.

>  It seems interesting and I wonder if it would'nt be better in case i wanted 
> to derive a new class from it from outside the module.

For a case as simple as in your example, I will go without metaclasses.
You could however change you function Form, which is an object factory,
i.e. return instances and not classes, to a true class factory by using
the built-in metaclass type(name,bases,clsdict). See one of my recent
postings for an example. This is meaningful, of course, only if you need more
than one instance of Form1 and Form2, or if you plan to subclasses Form1
or Form2, or doing more complicated stuff. You could for instance inherit
both from Form1 and Form2, by checking for name clashes and possibly
changing the name of clashing methods. This you can do with or without
metaclasses. 
Have fun,

                   Michele



More information about the Python-list mailing list