开发者

None in boost.python

开发者 https://www.devze.com 2022-12-19 04:31 出处:网络
I am trying to translate the following code d = {} d[0] = None 开发者_C百科 into C++ with boost.python

I am trying to translate the following code

d = {}
d[0] = None
开发者_C百科

into C++ with boost.python

boost::python::dict d;
d[0] = ?None

How can I get a None object in boost.python?


There is no constructor of boost::python::object that takes a PyObject* (from my understanding, a ctor like that would invalidate the whole idea if mapping Python types to C++ types anyway, because the PyObject* could be anything). According to the documentation:

object();

Effects: Constructs an object managing a reference to the Python None object.


You could use:

d[0] = d.get(0)

d.get defaults to None if you don't specify a default value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号