Convert std::complex<float> into a pybind11::object

Viewed 59

I have a std::complex<float> and want to use pybind11 to convert that value into a temporary pybind11::object (storing a complex python value). How do I do this?

1 Answers

Use pybind11::cast.

std::complex<float> a{1, 2};
pybind11::object obj = pybind11::cast(a);
Related