make a class instance from a string ?

Diez B. Roggisch deets at nospam.web.de
Thu Feb 23 05:57:32 EST 2006


Bo Yang wrote:

> Hi,
> I know in java , we can use
> 
> class.ForName("classname")
> 
> 
> to get an instance of the class 'classname' from a
> string , in python , how do I do that ?

You can use

  getattr(module, classname)(*arguments)


Diez





More information about the Python-list mailing list