May-13-2017, 09:57 AM
Several months ago I had a similar problem - dynamic import in Python3. This is my solution - luckily, I've preserved it
def dynamic_import(module_name, path2module): """ Dynamic import of module :param module_name: name of module :param path2module: path to module :return: module object """ dynamic_spec = imp_util.spec_from_file_location( module_name, '{}/{}.py'.format(path2module, module_name)) dynamic_module = imp_util.module_from_spec(dynamic_spec) dynamic_spec.loader.exec_module(dynamic_module) return dynamic_module
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.