Classes | Functions
iostream.h File Reference
#include "pybind11.h"
#include <streambuf>
#include <ostream>
#include <string>
#include <memory>
#include <iostream>
Include dependency graph for iostream.h:
This graph shows which files directly or indirectly include this file:

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, std::string name="ostream_redirect")
 

Function Documentation

class_<detail::OstreamRedirect> add_ostream_redirect ( module  m,
std::string  name = "ostream_redirect" 
)
inline

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()

Definition at line 209 of file iostream.h.



gtsam
Author(s):
autogenerated on Sat May 8 2021 02:51:30