I have a Boost Python object
py::object obj = whatever();
I want to print it using normal python rules.
// I want the effect of print 'My object is ', obj
std::cout << "My object is " << obj << std::endl;
This does not compile with a huge compiler dump. How do I do this?
operator<<(ostream &)defined forpy::object.str()function passingobjas the argument, and convert the return value to anstd::string, and stream that out. You could provide your ownoperator<<(ostream &, py::object const &)to provide the streaming operator for all Python objects using this approach.