__import__ with dict values

alex goretoy aleksandr.goretoy at gmail.com
Thu Mar 12 07:27:35 EDT 2009


__import__(opt['imp_mod']).options

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

how to make top work like bottom?
-Alex Goretoy
http://www.goretoy.com



On Thu, Mar 12, 2009 at 5:56 AM, alex goretoy
<aleksandr.goretoy at gmail.com>wrote:

> note i would still like to be able to do __import__("sys")."path"
>
> maybe if __import__ had __str__ defined, How is my thinking on this?
> and how would I achieve something like this?
> -Alex Goretoy
> http://www.goretoy.com
>
>
>
> On Thu, Mar 12, 2009 at 5:44 AM, alex goretoy <aleksandr.goretoy at gmail.com
> > wrote:
>
>> or eval for that matter
>> -Alex Goretoy
>> http://www.goretoy.com
>>
>>
>>
>> On Thu, Mar 12, 2009 at 5:43 AM, alex goretoy <
>> aleksandr.goretoy at gmail.com> wrote:
>>
>>> yay, no more
>>>
>>> exec ("import " + "sys")
>>>
>>> in my code
>>>
>>> -Alex Goretoy
>>> http://www.goretoy.com
>>>
>>>
>>>
>>> On Thu, Mar 12, 2009 at 5:42 AM, alex goretoy <
>>> aleksandr.goretoy at gmail.com> wrote:
>>>
>>>> I have resolved this problem in my code. It has something to do with
>>>> your current working directory when you append cwd/jars to sys.path and try
>>>> to import from interactive console
>>>> -Alex Goretoy
>>>> http://www.goretoy.com
>>>>
>>>>
>>>>
>>>> On Thu, Mar 12, 2009 at 4:58 AM, alex goretoy <
>>>> aleksandr.goretoy at gmail.com> wrote:
>>>>
>>>>> How would I import with __import__ from dict values?
>>>>> I want sys.path value inside d['syspath'], below code doesn't work for
>>>>> me
>>>>>
>>>>>
>>>>> d={}
>>>>> d['sys']='sys'
>>>>> d['path']='path'
>>>>>
>>>>> d['syspath']=__import__(d['sys'],fromlist=[d['path']])
>>>>>
>>>>> and how come does  above line doesn't give me diff value than below
>>>>> line?
>>>>>
>>>>> d['syspath']=__import__(d['sys'])
>>>>>
>>>>> Meaning, when I do this doesn't work. Which makes sense.
>>>>> d['syspath']()
>>>>> d['syspath'].d['path']
>>>>>
>>>>> but this works both with fromlist and without.
>>>>>
>>>>> d['syspath'].path
>>>>>
>>>>>
>>>>> -Alex Goretoy
>>>>> http://www.goretoy.com
>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090312/83e01db5/attachment-0001.html>


More information about the Python-list mailing list