Reputation: 13
I am using pybind11 to call a python built-in function like range in c++ code. But I only found way to call a function in module like this:
py::object os = py::module::import("os");
py::object makedirs = os.attr("makedirs");
makedirs("/tmp/path/to/somewhere");
But a python built-in function like range needn't import any modules, so how can I use pybind11 to call range in c++ code?
Upvotes: 1
Views: 704
Reputation: 43
You can also import the builtins
module which contains all the built-in python functions.
In your case it would be something like:
py::object builtins = py::module_::import("builtins");
py::object range = builtins.attr("range");
range(0, 10);
Upvotes: 0