Can you create a class from a string name
revanna at mn.rr.com
Sat Mar 1 22:36:43 CET 2003
On Sat, 01 Mar 2003 20:45:31 +0000, Vivek Sawant wrote:
> is there a way to create a class object or an instance object for a
> class if you have the name of the class as a string at the runtime.
> For example, in Java you can create a 'Class' object as:
> Class.forname ('<classname>')
I don't know about Java.... But, from your question, it sounds like you're
asking about an object factory.
def factory(aClass, *args):
so if you have a class Spam, that takes 2 args, during runtime, you can
newobject=factory(Spam, arg1, arg2)
More information about the Python-list