Importing at runtime

Devan L devlai at gmail.com
Tue Oct 25 07:21:15 CEST 2005


http://www.python.org/doc/2.4.2/lib/built-in-funcs.html

or, if you want an answer in code now and don't want to read the docs

def my_import(name):
    module = __import__(name)
    globals()[name] = module #not a good idea

Or, seeing as how you won't be directly accessing them by name, anyways

modules = [__import__(name) for name in module_names]




More information about the Python-list mailing list