How do you pass kwargs to a boost-python wrapped function?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 09:56:28

After some investigation, it turns out that the object function call operator is overridden for two arguments of type args_proxy and kwds_proxy. So you have to use this specific call style of two arguments.

args_proxy and kwds_proxy are generated by the * overloads. This is really nice.

Additionally, the first argument must be a tuple type so that the python interpreter correctly handles the *args argument.

The resulting example works:

boost::python::list arguments;
arguments.append("aMessage");
arguments.append("1");

boost::python::dict options;
options["source"] = "cpp";

boost::python::object python_func = get_python_func_of_wrapped_object()
python_func(*boost::python::tuple(arguments), **options)

Hope this helps...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!