I want to import some package depending on which value the user chooses.
The default is file1.py:
file1.py
Old thread, but I needed the answer, so someone else still might...
There's a cleaner way to do this in Python 2.7+:
import importlib my_module = importlib.import_module("package.path.%s" % module_name)