我将一个 python 模块作为PyObject
. 我想检查这个值是否在我的 C 代码中为 NONE,使用这种形式:
int func(PyObject tmp)
{
if(tmp)
{
// etc
我收到以下错误。如何从 PyObject 转换为布尔值,类似于 Python 的 if 函数的行为方式。值得注意的是,当tmp
是一个boost::python::object
变量时,此命令按预期工作。
ex_program.cpp:72:7: error: value of type 'PyObject' (aka '_object') is not contextually convertible to 'bool'
if (tmp)
^~~