Dynamically importing modules

Jared Lee Peterson jared at difinium.com
Wed Jun 20 14:25:50 EDT 2001

I have a quick question about importing modules.  I would like to have a
script that in sitting in a directory and in this directory I want to
have sub directories that represent modules to that script.  However
I do not want this script to have any prior knowledge of what modules
may exist.  So I would like for the script to look at it current working
directory and then try to load each module that does exist through the
use of import.  But I can not seem to figure out how to get import to
work for me.  Because I need to be able to loop through a list
(os.listdir()) of the subdirectories/modules that the script has found
and try to import them.  Does anyone have any suggestions?  Does this
even make sense?


More information about the Python-list mailing list