Python class instantiation using name

Amol P Dharmadhikari ad at cs.usfca.edu
Tue Dec 17 16:38:06 EST 2002


Hi All,

I have a question about python, which I did not find answered in
the FAQs and tutorials.

Is it possible to create an instance of a class using its name?
If so how?

So in general, if I have a string which contains the name of a class,
how do I create an instance of that class?

i.e. something similar to what the below java code snippet can do
Object o = java.lang.Class.forName(className).newInstance()

Please cc me in the reply as I am not subscribed to the list.

Thanks in advance.

- Amol




More information about the Python-list mailing list