C
Carlos Ribeiro
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)
and:
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
other?
--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: (e-mail address removed)
mail: (e-mail address removed)
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)
and:
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
other?
--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: (e-mail address removed)
mail: (e-mail address removed)