make a class instance from a string ?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Feb 23 05:44:42 EST 2006


Bo Yang:
> to get an instance of the class 'classname' from a
> string , in python , how do I do that ?

This is a possibile way:

class C: pass
c = locals()["C"]()
print c

Bye,
bearophile




More information about the Python-list mailing list