I would like to do the equivalent of this python import statement
from module import func1, func2, func3, var1, var2, ...
but the module name and location are passed to the script as command line arguments, so I'm using importlib.util. Is there a more pythonic way to get the variable names into the main module's namespace?
import importlib.util
import sys
modulepath = sys.argv[1]
spec = importlib.util.spec_from_file_location('modulename', modulepath)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
# Is there a better way than this?
func1 = module.func1
func2 = module.func2
func3 = module.func3