how to import a name from a module-path?
BjornSteinarFjeldPettersen at gmail.com
Tue Jun 16 13:25:19 EDT 2009
I'm storing the path to functions in a database and now I'd like to
get a reference so I can execute them.
I looked briefly at the imp module and got very confused... Currently
I'm doing this:
module, obj = path.rsplit('.', 1)
exec "from rootpkg.%s import %s as fn" % (module, obj)
function = import_object('mypackage.mymodule.myfunction')
this is happening in a trusted environment, so I'm not worried about
Are there more elegant ways of doing this (ie. without exec)?
More information about the Python-list