python - 如何使用 pybind11 传递 Python 的关键字参数?
问题描述
给定这个函数:__init__(username, password, **kwargs)
使用这些关键字参数:
auto_patch:修补 api 对象以匹配公共 API。默认值:假
drop_incompat_key:删除不在公共 API 中的 api 对象密钥。默认值:假
timeout:超时间隔,以秒为单位。默认值:15
api_url: 覆盖默认的 api url base
cookie:上一个会话中保存的 cookie 字符串
设置:上一个会话的设置字典
on_login:登录成功后的回调
代理:指定代理例如:'<a href="http://127.0.0.1:8888" rel="nofollow noreferrer">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;
}
解决方案
我找到了正确的文档:https ://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html
我无法测试它,因为我遇到了一些其他问题,但那是去的地方。
推荐阅读
- javascript - 对JS对象中的解构元素执行操作
- bixby - 如何通过 DateTimeExpression 在 Bixby 中单击设置值
- node.js - Axios 库在我的 post 请求端点参数之间添加了额外的“/”
- sql - 如何在 SQL 查询中添加和分组项目
- google-apps-script - 如何在运行谷歌应用脚本时显示负载指示器
- logstash - Logstash 无法改变文本日志
- swift - 呈现 - 在 SwiftUI 顶部显示视图(我不想导航)
- docker - Docker 没有在代理下连接
- vb.net - VB 在启动画面上加载照片
- php - Doctrine - 返回不为 0 的结果