Gabriel,<br><br>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?<br><br>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<br>
<br>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?<br><br clear="all">-Alex Goretoy<br><a href="http://www.goretoy.com">http://www.goretoy.com</a><br>
<br>
<br><br><div class="gmail_quote">On Thu, Mar 12, 2009 at 1:00 PM, Gabriel Genellina <span dir="ltr"><<a href="mailto:gagsl-py2@yahoo.com.ar">gagsl-py2@yahoo.com.ar</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
En Thu, 12 Mar 2009 09:27:35 -0200, alex goretoy <<a href="mailto:aleksandr.goretoy@gmail.com" target="_blank">aleksandr.goretoy@gmail.com</a>> escribió:<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

note i would still like to be able to do __import__("sys")."path"<br>
</blockquote></blockquote>
<br></div>
p = __import__("sys").path<br>
<br>
That's a convoluted way of doing:<br>
<br>
import sys<br>
p = sys.path<br>
<br>
(except that the latter one inserts "sys" in the current namespace)<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

maybe if __import__ had __str__ defined, How is my thinking on this?<br>
and how would I achieve something like this?<br>
</blockquote></blockquote>
<br></div>
__str__ has absolutely nothing to do.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
__import__(opt['imp_mod']).options<br>
<br>
eval(opt['imp_mod']+"."+opt['imp_opt'])<br>
<br>
how to make top work like bottom?<br>
</blockquote>
<br></div>
If you think you have to use eval: you don't. Never.<br>
<br>
module = __import__(opt['imp_mod'])<br>
module.options<br>
<br>
If the name "options" is not known until runtime, use getattr:<br>
<br>
getattr(module, name_of_attribute)<br>
<br>
The above assumes you want an attribute (like logging.ERROR). If you want a sub-module (a module inside a package) use __import__("<a href="http://dotted.name" target="_blank">dotted.name</a>") and then retrieve the module by name from sys.modules; see <a href="http://docs.python.org/library/functions.html#__import__" target="_blank">http://docs.python.org/library/functions.html#__import__</a><br>

<br>
<br>
-- <br>
Gabriel Genellina<br><font color="#888888">
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>