I wrote a small script. It's designed to search the python directory for all available modules (whether they are installed or not), then it is supposed to check what modules are currently loaded, then it offers an option to dynamically load a module of your choice. The latter using __import__()
because I am passing a string to it - (this is where I am having a problem - but I'll get back to it shortly)...then it gives the option to "browse" the module for all its classes, functions, etc. (using dir([module name])
...).
The problem:
When the module is loaded dynamically - it is embedded in a try/except
statement - if it succeeds it reports that the "module is loaded" and if it fails it reports...duh..."Failed to load..."
If you type the name of a module, for example a module named "uu", it says "loaded". So I know it is loading - however, when I go back and call the function that checks all of the LOADED modules - it is blank (using sys.modules
)
I am thinking that python is loading the module into a temporary place which is not sys.modules
because when I exit out of the script and check sys.modules
it is not there.