Redirect Streams’s Documentation¶
Description¶
This project provides Python context managers to help redirect multiple forms of output into a buffer (capturing the output). This documentation provides information on how to install, use, and contribute to this project.
Contents:
Project Roadmap¶
This project is currently under development and is not ready to be used. This should change in the next few versions:
- Version 0.1: Project Scaffolding
- Version 0.2: Decorators working in Python 3.4
- Version 0.3: Documentation for Project
- Version 0.4: Support for Python 2.6, 2.7
- Version 0.5: Support for Python 3.3, 3.4 (And maybe 3.2)
- Version 0.6: Solicit Help :D
Installation¶
The project may be installed via pip:
$ pip install redirect-streams
To install the development version:
$ pip install git+git://github.com/jambonrose/redirect_streams
Usage¶
Basic Usage¶
The most common use of this project is to redirect stdout
.
from io import BytesIO, SEEK_SET, TextIOWrapper
from os import system
from sys import stdout
from redirect_streams import redirect_stdout
with TextIOWrapper(BytesIO(), stdout.encoding) as buffer:
with redirect_stdout(buffer):
print('this will be saved in the buffer')
# code below won't work with stdlib's redirect_stdout
system('this will be saved in the buffer')
buffer.seek(SEEK_SET)
saved = buffer.read()
print(saved)