Skip to content

Instantly share code, notes, and snippets.

@Rustam-Z
Created February 25, 2022 16:56
Show Gist options
  • Save Rustam-Z/ee976d93131dc7f9b4891d5b8e755d89 to your computer and use it in GitHub Desktop.
Save Rustam-Z/ee976d93131dc7f9b4891d5b8e755d89 to your computer and use it in GitHub Desktop.
Import Python modules using strings
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