How do I get string representation of PyObject in Python3?

Viewed 2246

I am debugging Python source code (CPython 3.4). I'm receiving a PyObject*. I would like to printf it.

For example (from Objects/floatobject.c of Python 3.4 source code):

PyObject *o_ndigits = NULL;
Py_ssize_t ndigits;

x = PyFloat_AsDouble(v);
if (!PyArg_ParseTuple(args, "|O", &o_ndigits))
    return NULL;

How do I printf o_ndigits? It is almost same as this question: Python: get string representation of PyObject?, but for Python3. With original solution, I got "undefined reference to PyString_AsString" error.

1 Answers
Related