简体   繁体   中英

How to pass Python's keyword arguments with pybind11?

Given this function: __init__(username, password, **kwargs) with these keyword arguments:

  • auto_patch: Patch the api objects to match the public API. Default: False

  • drop_incompat_key: Remove api object keys that is not in the public API. Default: False

  • timeout: Timeout interval in seconds. Default: 15

  • api_url: Override the default api url base

  • cookie: Saved cookie string from a previous session

  • settings: A dict of settings from a previous session

  • on_login: Callback after successful login

  • proxy: Specify a proxy ex: ' http://127.0.0.1:8888 ' (ALPHA)

  • proxy_handler: Specify your own proxy handler

I want to embed python in my C++ application with pybind11. How do I pass the keyword arguments? I am this far:

#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;
}

I have found the right documentation: https://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html

I cannot test it as I have some other issues occurring but that is the place to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM