相关疑难解决方法(0)

你如何将kwargs传递给boost-python包装函数?

我有一个带有此签名的python函数:

def post_message(self, message, *args, **kwargs):
Run Code Online (Sandbox Code Playgroud)

我想从c ++调用函数并传递给它一些kwargs.调用函数不是问题.知道如何通过kwargs是.这是一个非工作的释义样本:

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

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

boost::python::object python_func = get_python_func_of_wrapped_object()
python_func(message, arguments, options)
Run Code Online (Sandbox Code Playgroud)

当我运用这段代码时,在pdb中我得到了(这不是我想要的):

messsage = aMessage
args = (['1'], {'source': 'cpp'})
kwargs = {}
Run Code Online (Sandbox Code Playgroud)

你如何在我的例子中传递**kwargs字典中的选项

我看过一篇建议使用**选项语法的帖子(这有多酷!):

python_func(message, arguments, **options)
Run Code Online (Sandbox Code Playgroud)

不幸的是,这导致了

TypeError: No to_python (by-value) converter found for C++ type: class boost::python::detail::kwds_proxy
Run Code Online (Sandbox Code Playgroud)

感谢您提供任何帮助.

kwargs boost-python

13
推荐指数
1
解决办法
2220
查看次数

标签 统计

boost-python ×1

kwargs ×1