Check if PyObject is None

前端 未结 1 1464
借酒劲吻你
借酒劲吻你 2021-02-05 07:00

I would just like to check if a PyObject that I have is None. I naively expected that any None Pyobject * returned from a fun

1条回答
  •  梦如初夏
    2021-02-05 07:37

    You can just compare directly with Py_None using ==:

    if (obj == Py_None)
    

    From the docs:

    Note that the PyTypeObject for None is not directly exposed in the Python/C API. Since None is a singleton, testing for object identity (using == in C) is sufficient. There is no PyNone_Check() function for the same reason.

    0 讨论(0)
提交回复
热议问题