def debug_func(idx, best_p, best_fun, msg): print 'best attempt: ', idx, '- fun:', best_fun, '\n', best_p if key is None: info = str(msg) else: info = str(key) debug_write_fit(best_p, f, rf, channel_w, patch_w, mode, info, model='dog', path=debug_output_path)