Importing at runtime

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

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