我有一个 Python 函数,其签名如下:
def post_message(self, message, *args, **kwargs):
我想从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)
当我运行这段代码时,在pdb中我得到了以下结果(这不是我想要的):
messsage = aMessage
args = (['1'], {'source': 'cpp'})
kwargs = {}
在我的示例中,如何将选项传递到**kwargs字典中?
我看过一个帖子建议使用**options语法(这是多酷啊!):
python_func(message, arguments, **options)
不幸的是,这会导致
TypeError: No to_python (by-value) converter found for C++ type: class boost::python::detail::kwds_proxy
非常感谢您能提供的任何帮助。
python_func(*boost::python::tuple(), **options)
。 - luator