Python: get string representation of PyObject?

前端 未结 5 1365
予麋鹿
予麋鹿 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:18

    Try PyObject_Repr (to mimic Python's repr) or PyObject_Str (to mimic Python's str).

    Docs:

    Compute a string representation of object o. Returns the string representation on success, NULL on failure. This is the equivalent of the Python expression repr(o). Called by the repr() built-in function.

提交回复
热议问题