En Thu, 12 Mar 2009 09:27:35 -0200, alex goretoy <aleksandr.gore...@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:

import sys
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.

__import__(opt['imp_mod']).options

eval(opt['imp_mod']+"."+opt['imp_opt'])

how to make top work like bottom?

If you think you have to use eval: you don't. Never.

module = __import__(opt['imp_mod'])
module.options

If the name "options" is not known until runtime, use getattr:

getattr(module, name_of_attribute)

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 http://docs.python.org/library/functions.html#__import__


--
Gabriel Genellina

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

Reply via email to