Recently, I tried to figure out what is the actual result of PyEval_EvalCodeEx call from the Python C API. The documentation is less than sparse. Obviously, the function returns result of expression evaluation. The result is returned as pointer to
PyObject, but the type has a bit opaque nature, so means nothing without querying and inspecting underlying data.
Luckily, I have received a couple of answers on the Python mailing list as well as from ACCU folks . Here is very quick summary of the
- first and foremost, know C as well as Python
- it evaluates an expression, any valid Python expression
- it wraps the builtin
- its return value is exactly the same as the return value of an equivalent call to the
- if the
PyObject *coargument was compiled with start argument
Py_eval_inputdenoting a single expression, the function returns value produced as the result of the expression
Py_single_inputcompilation mode was used, then the result of will be
- it returns
PyObject*, so - as Russel Winder suggested - Do type analysis regarding the object being pointed at you have to do it the hard way! PyObject_IsInstance, or if you are eeling really hard :-) PyObject_Type. There is also PyPobject_TypeCheck.
I can’t do it now, but I’m going to check if all those statements are correct.