Loading classes dynamically

Ramza Brown berlin.brown at gmail.com
Sun Aug 14 22:15:30 EDT 2005


What is the most pythonic way to load a class and instaniate an object 
dynamically.  Right now, I am using eval:

try:
      load = eval('%s(props)' % (props['plugin.generate']))
except:

It works, doesnt seem very safe.  Where props['plugin.generate'] is a 
class name string.  And 'props' is the first arg in the constructor.

What do you think?

-- 
Ramza from Atlanta
http://www.newspiritcompany.com



More information about the Python-list mailing list