How To Dynamically Import Python Modules

Here’s how you import a python module dynamically: say your module is called “mysettings” and it’s in the directory “config”. Make sure you have a __init__.py in your “config” directory and use:

mysettings = __import__("config.mysettings", fromlist=["config"])

This is equivalent to

from config import mysetings