Can you create a class from a string name
Alex Martelli
aleax at aleax.it
Sat Mar 1 17:19:08 EST 2003
Anna wrote:
...
> def factory(aClass, *args):
> return apply(aClass,args)
Note that this needs aClass to be a class object, not a class name. And
in today's Python, apply's rather redundant -- the body of this factory
function might just as well be:
return aClass(*args)
since the * form can now be applied on calling, symmetrically to its
application in def (it expands any sequence of arguments). So you might
equally well define, in modern Python:
factory = aClass
Alex
More information about the Python-list
mailing list