Created
February 25, 2022 16:56
-
-
Save Rustam-Z/ee976d93131dc7f9b4891d5b8e755d89 to your computer and use it in GitHub Desktop.
Import Python modules using strings
This file contains 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 | |
# Contrived example of generating a module named as a string | |
full_module_name = "tables." + "tasks" | |
# The file gets executed upon import, as expected. | |
mymodule = importlib.import_module(full_module_name) | |
# Then you can use the module like normal | |
var = mymodule.COLUMNS | |
print(var) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment