i wrote the C code as follow:
int main(int argc, char** argv)
{
PyObject *mod, *name, *func;
Py_Initialize();
mod = PyImport_ImportModule("perf_tester");
if(!mod)
{
printf("cannot find perf_tester.py");
getchar();
return -1;
}
name = PyObject_GetAttrString(mod, "CheckSharpness");
if(!name)
{
printf("can not find CheckSharpness");
getchar();
return -1;
}
func = PyObject_GetAttrString(name,"F");
if(!func)
{
printf("can not find function");
getchar();
return -1;
}
Py_Finalize();
system("pause");
return 0;
}
except for func, i could find mod and name.
and the partial of the perf_tester.py as follow:
def CheckSharpness(sample, edges, min_pass_mtf, min_pass_lowest_mtf,
use_50p, mtf_sample_count, mtf_patch_width,
mtf_crop_ratio=_MTF_DEFAULT_CROP_RATIO,
n_thread=1):
mtfs = [mtf_calculator.Compute(sample, line_start[t], line_end[t],
mtf_patch_width, mtf_crop_ratio,
use_50p)[0] for t in perm]
F = open("data.txt","w")
F.write(str(mtfs))
F.close()
what could I do?
Fred Foo
365k80 gold badges765 silver badges852 bronze badges
1 Answer 1
F is a local variable, it's not a member of CheckSharpness. It does not exist when CheckSharpness is not currently running, and each invocation of CheckSharpness has its own copy. There's no way to access this from outside.
answered May 8, 2014 at 9:34
Angew is no longer proud of SO
172k18 gold badges377 silver badges478 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
PyErr_PrintEx(0)whenever a Python C API function fails. Also, don't tag C question asc++, please.