Skip to content Skip to sidebar Skip to footer

How To Call A Builtin Function (or Method) From C Code Of A Python Extension Module?

What I currently want to accomplish is to tweak Pythons itertools module function combinations to sort the passed iterable before creating combinations out of it with the goal of

Solution 1:

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);

Post a Comment for "How To Call A Builtin Function (or Method) From C Code Of A Python Extension Module?"