Instantiating an object when the type is only known at runtime

Samuel knipknap at gmail.com
Tue Oct 3 09:46:03 EDT 2006


Hi,

I am trying to replace the eval() in the following code:

def myfunc(type, table):
    module   = __import__(type)
    type     = 'module' + '.' + type
    obj      = eval(type)
    return obj(row[table.c.name], row[table.c.handle])

I am out of ideas. Any hints?

Thanks,
-Samuel




More information about the Python-list mailing list