__import__ with dict values
gagsl-py2 at yahoo.com.ar
Thu Mar 12 19:00:40 CET 2009
En Thu, 12 Mar 2009 09:27:35 -0200, alex goretoy
<aleksandr.goretoy at gmail.com> escribió:
>> note i would still like to be able to do __import__("sys")."path"
p = __import__("sys").path
That's a convoluted way of doing:
p = sys.path
(except that the latter one inserts "sys" in the current namespace)
>> maybe if __import__ had __str__ defined, How is my thinking on this?
>> and how would I achieve something like this?
__str__ has absolutely nothing to do.
> how to make top work like bottom?
If you think you have to use eval: you don't. Never.
module = __import__(opt['imp_mod'])
If the name "options" is not known until runtime, use getattr:
The above assumes you want an attribute (like logging.ERROR). If you want
a sub-module (a module inside a package) use __import__("dotted.name") and
then retrieve the module by name from sys.modules; see
More information about the Python-list