'Convert the code (which is a string) into a callable object.'

def _create_callable_object(self, code):

    class code_wrapper:
        def __init__(self, code):
            code += '\n\nres    =    customized_distance(a,b)\n'
            self._compiled_code = compile(code, '<string>', 'exec')
        def __call__(self, a, b):
            globals_eval = {'a': a, 'b': b, 'res': None}
            eval(self._compiled_code, globals_eval)
            return globals_eval['res']
    return code_wrapper(code)
