【问题标题】:How to pass Python's keyword arguments with pybind11?如何使用 pybind11 传递 Python 的关键字参数?
【发布时间】:2019-08-23 07:18:51
【问题描述】:

给定这个函数:__init__(username, password, **kwargs) 带有这些关键字参数:

  • auto_patch:修补 api 对象以匹配公共 API。默认值:假

  • drop_incompat_key:删除不在公共 API 中的 api 对象键。 默认值:假

  • timeout:超时间隔,以秒为单位。默认值:15

  • api_url:覆盖默认的api url base

  • cookie:上一个会话中保存的 cookie 字符串

  • 设置:上一个会话的设置字典

  • on_login:登录成功后回调

  • 代理:指定代理例如:'http://127.0.0.1:8888' (ALPHA)

  • proxy_handler:指定您自己的代理处理程序

我想用 pybind11 将 python 嵌入到我的 C++ 应用程序中。 我如何传递关键字参数?我已经这么远了:

#include <pybind11/embed.h> // everything needed for embedding
#include <iostream>
namespace py = pybind11;

int main()
{
    py::scoped_interpreter guard{}; // start the interpreter and keep it alive

    py::module calc = py::module::import("calc");
    py::object result = calc.attr("__init__")("IGname", "IGpassword");

    int i;
    std::cin >> i;
}

【问题讨论】:

    标签: python c++ embed pybind11


    【解决方案1】:

    我找到了正确的文档:https://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html

    我无法对其进行测试,因为我遇到了一些其他问题,但这是要去的地方。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      • 2017-06-13
      • 2022-12-25
      • 1970-01-01
      • 1970-01-01
      • 2020-03-08
      • 2021-07-08
      相关资源
      最近更新 更多