How to call a builtin function (or method) from C code of a Python extension module?

前端 未结 1 1855
别跟我提以往
别跟我提以往 2021-01-23 11:35

What I currently want to accomplish is to tweak Pythons itertools module function combinations to sort the passed iterable before creatin

相关标签:
1条回答
  • 2021-01-23 11:44

    You should get the sorted function out of the builtins and than call it:

    PyObject *builtins = PyEval_GetBuiltins(); 
    PyObject *sorted = PyDict_GetItemString(builtins , "sorted");
    PyObject *sorted_list = PyEval_CallFunction(sorted, "(O)", iterable);
    
    //... do something with the sorted_list
    
    Py_DECREF(sorted_list);
    
    0 讨论(0)
提交回复
热议问题