I have a program which automatically generates a data structure from user-provided JSON code. I also want to provide an option to allow users to write their own function to generate this data structure programmatically. Is there a way for Python to load an arbitrary module by path and return that module's namespace so I can call the user's function from my program?
Example, I want something like the following:
def make(custom):
if not custom:
return helper('example.json')
else:
return load('path/to/user-script.py').make() # this line here