Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python
function to do dynamic import?
 

Index | Next | Previous | View Flat


david at asdf

Sep 10, 2007, 10:52 PM


Views: 59
Permalink
function to do dynamic import?

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.

---
>>> def gim():
... exec "import gamel"
...
>>> gim()
>>> sys.modules["gamel"]
<module 'gamel' from 'c:\gamel.pyc'>
>>>gamel
NameError: name 'gamel' is not defined
>>>exec "import gamel"
>>>gamel
<module 'gamel' from 'c:\gamel.pyc'>


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

Subject User Time
function to do dynamic import? david at asdf Sep 10, 2007, 10:52 PM
    Re: function to do dynamic import? attn.steven.kuo at gmail Sep 10, 2007, 11:12 PM
    Re: function to do dynamic import? jcd at sdf Sep 11, 2007, 4:20 AM
    Re: function to do dynamic import? steve at holdenweb Sep 11, 2007, 5:24 AM
    Re: function to do dynamic import? david at asdf Sep 11, 2007, 6:54 PM
        Re: function to do dynamic import? __peter__ at web Sep 12, 2007, 2:37 AM
    Re: function to do dynamic import? david at asdf Sep 11, 2007, 6:57 PM
    Re: function to do dynamic import? david at asdf Sep 11, 2007, 7:34 PM
        Re: function to do dynamic import? steve at holdenweb Sep 11, 2007, 8:14 PM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.