Creating new classes on the fly

Carlos Ribeiro carribeiro at
Tue Oct 5 22:53:35 CEST 2004

I need to create new classes on the fly with different default
parameters, stored as class attributes. Of course, there's a reason
behind it: I need new classes, because I need to be able to build
multiple instances of them later. And I need new defaults, because the
values can't be provided at instantiation time (because of scoping &
mutability issues).

I've found two different ways to do it in the documentation:

new.classobj(name, baseclasses, dict)


type(name, bases, dict)

I assume that both end up calling the same code, but I really don't
know which one am I supposed to call, in terms of being the most
'pythonic' way. Are both the same? Is one of them preferred over the

Carlos Ribeiro
Consultoria em Projetos
mail: carribeiro at
mail: carribeiro at

More information about the Python-list mailing list