How to import a module given its name as string?
With Python older than 2.7/3.1, that’s pretty much how you do it. For newer versions, see importlib.import_module for Python 2 and Python 3. You can use exec if you want to as well. Or using __import__ you can import a list of modules by doing this: >>> moduleNames = [‘sys’, ‘os’, ‘re’, ‘unittest’] >>> moduleNames … Read more