Python: get string representation of PyObject?

前端 未结 5 1386
予麋鹿
予麋鹿 2020-12-23 19:41

I\'ve got a C python extension, and I would like to print out some diagnostics.

I\'m receiving a string as a PyObject*.

What\'s the canonical way to obtain a

5条回答
  •  悲哀的现实
    2020-12-23 20:17

    If you need just print the object in Python 3 you can use one of these functions:

    static void print_str(PyObject *o)
    {
        PyObject_Print(o, stdout, Py_PRINT_RAW);
    }
    
    static void print_repr(PyObject *o)
    {
        PyObject_Print(o, stdout, 0);
    }
    

提交回复
热议问题