#include "pybind11.h"
#include <algorithm>
#include <cstring>
#include <iostream>
#include <iterator>
#include <memory>
#include <ostream>
#include <streambuf>
#include <string>
#include <utility>
Go to the source code of this file.
Classes | |
class | OstreamRedirect |
class | pythonbuf |
class | scoped_estream_redirect |
class | scoped_ostream_redirect |
Functions | |
class_< detail::OstreamRedirect > | add_ostream_redirect (module_ m, const std::string &name="ostream_redirect") |
|
inline |
\rst This is a helper function to add a C++ redirect context manager to Python instead of using a C++ guard. To use it, add the following to your binding code:
.. code-block:: cpp
#include <pybind11/iostream.h> ... py::add_ostream_redirect(m, "ostream_redirect");
You now have a Python context manager that redirects your output:
.. code-block:: python
with m.ostream_redirect(): m.print_to_cout_function()
This manager can optionally be told which streams to operate on:
.. code-block:: python
with m.ostream_redirect(stdout=true, stderr=true): m.noisy_function_with_error_printing()
\endrst
Definition at line 258 of file iostream.h.