Dynamic creation of an object instance of a class by name

Andre Meyer meyer at acm.org
Wed Apr 7 11:36:54 EDT 2004


Diez B. Roggisch <deetsNOSPAM <at> web.de> writes:

> 
> cn = 'A'
> inst = eval('%s()' % cn)
> 


Thanks!

What about parameters? Do they go into the %s()?

How does this compare to:

cn = 'A'
inst = eval(cn)(arg0, arg1)

kind regards
Andre






More information about the Python-list mailing list