def factory(name): for fname, obj in inspect.getmembers(sys.modules[__name__]): if inspect.isfunction(obj): if fname == name: return obj from otest.func import factory as ofactory return ofactory(name)
def _get_func(dic, func_factory): """ Convert function names into function references :param dic: A key, value dictionary where keys are function names :param func_factory: Factory function used to find functions :return: A dictionary with the keys replace with references to functions """ res = {} for fname, val in dic.items(): func = func_factory(fname) if func is None: func = ofactory(fname) if func is None: raise Exception("Unknown function: '{}'".format(fname)) res[func] = val return res