"Samuel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> 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?

Perhaps what you need is a dict 'types' mapping strings to types/classes.
Then the last two lines might become

  return types[type](row[table.c.name], row[table.c.handle])

The trick of mapping names to callables for runtime choice of what to call 
has several uses.

Terry Jan Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to