function to do dynamic import?

bambam david at asdf.asdf
Tue Sep 11 21:54:51 EDT 2007


<attn.steven.kuo at gmail.com> wrote in message 
news:1189491152.601490.33880 at o80g2000hse.googlegroups.com...
> On Sep 10, 10:52 pm, "bambam" <da... at asdf.asdf> wrote:
>> import works in the main section of the module, but does
>> not work as I hoped when run inside a function.
>>
>> That is, the modules import correctly, but are not visible to
>> the enclosing (global) scope.
>>
>> Questions:
>> (1) Where can I read an explanation of this?
>> (2) Is there a work around?
>>
>> BTW, sys.modules("filename") shows that the module is
>> loaded, I just don't know how to use it when loaded that
>> way.  Also, if I import again at the global scope, the module
>> name becomes available.
>>
>> Steve.
>
>
>
> (snipped)
>
> This was recently discussed:
>
>    http://groups.google.com/group/comp.lang.python/msg/f6fcdf49710cb833
>
> --
> Hope this helps,
> Steven
>

def gim():
    exec "global gamel"
    exec "import gamel"

Unfortunately, does not have the desired effect.
Steve.





More information about the Python-list mailing list