本文介绍了检查PyObject是否为None的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想检查一下 PyObject 是否为 None 。我天真地期望从函数返回的任何无 Pyobject * 将是一个NULL指针,但是似乎

I would just like to check if a PyObject that I have is None. I naively expected that any None Pyobject * returned from a function would be a NULL pointer, but that doesn't seem to be the case.

所以:如何检查我的 PyObject * 是否指向无对象?

So: how do I check if a PyObject * of mine points to a None object?

我知道有像 PyInt_Check(PyObject *),但我找不到像 PyNone_Check 。我想我可以检查我的 PyObject 和 Py_None 之间的平等,但结果是我甚至不知道

I know that there are macros like PyInt_Check(PyObject *) around, but I couldn't find anything like PyNone_Check. I thought I could just check the equality between my PyObject and Py_None, but turns out I don't even know how to make equality comparisons with this library.

推荐答案

您可以直接与 Py_None 使用 == :

if (obj == Py_None)

从:

这篇关于检查PyObject是否为None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 11:00