__import__ with dict values
aleksandr.goretoy at gmail.com
Fri Mar 13 02:00:30 CET 2009
Thank you. This makes sense to me. I will go with sys.modules. Can you give
me a good example how to do it getattr way?
currently I am having this problem in my code. Kinda off subject, but not
entirely. I set default variable in self.opt after that I import
jar.properties into self.opt['properties']. Now my self.opt doesn't have the
same defaults set. in other words we load our configuration properties. Then
we over write any configuration properties with supplied sys.argv[1::]
arguments I am passing my sys.argv to a class and inside the class I use
getopt to get site_name and files_name, also many other variable that
overwrite the configuration that is set from the jar.properties
This was working when I was using exec and eval. I was not able to just use
exec I had to use exec on import and eval on module.module it was wierd, can
someone tell me why?
On Thu, Mar 12, 2009 at 1:00 PM, Gabriel Genellina
<gagsl-py2 at yahoo.com.ar>wrote:
> 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:
> 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.
>> 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:
> 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
> Gabriel Genellina
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list