1

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?

1
  • You should call PyErr_PrintEx(0) whenever a Python C API function fails. Also, don't tag C question as c++, please. Commented May 8, 2014 at 9:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.