Instantiating an object when the type is only known at runtime

Samuel knipknap at
Tue Oct 3 15:46:03 CEST 2006


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[], row[table.c.handle])

I am out of ideas. Any hints?


More information about the Python-list mailing list