Created
September 24, 2024 19:04
-
-
Save alorence/5bfe71d51d4c90578cedef7ccf70fb33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import importlib | |
def import_all_from(module_path: str) -> None: | |
""" | |
This is a programmatic version of "from <module_path> import *" | |
It can be used to import all variables from specific settings file and inject it in current globals() | |
:param module_path: A dotted path to a python module | |
""" | |
module = importlib.import_module(module_path) | |
globals().update({key: value for key, value in module.__dict__.items() if not key.startswith("_")}) | |
import_all_from("project.settings.main") | |
import_all_from("project.settings.foo") | |
import_all_from("project.settings.bar") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment