簡體   English   中英

如何通過pybind11傳遞Python的關鍵字參數?

[英]How to pass Python's keyword arguments with pybind11?

給定此功能: __init__(username, password, **kwargs)具有以下關鍵字參數:

  • auto_patch:修補api對象以匹配公共API。 默認值:False

  • drop_incompat_key:刪除不在公共API中的api對象密鑰。 默認值:False

  • timeout:超時間隔,以秒為單位。 默認值:15

  • api_url:覆蓋默認的api URL庫

  • cookie:上一個會話中保存的cookie字符串

  • 設置:上一個會話的設置命令

  • on_login:成功登錄后的回調

  • proxy:指定一個代理,例如:' 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

我無法測試它,因為發生了其他一些問題,但這是可以解決的地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM