Easy stream redirection in Python.
Project description
Description
This project provides Python context managers to help redirect multiple forms of output into a buffer (capturing the output).
Installation
$ pip install redirect-streams
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)
For other context managers and more detailed information, please refer to the documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
redirect-streams-0.1.0.zip
(6.2 kB
view hashes)
redirect-streams-0.1.0.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for redirect_streams-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88cf4c3f30f295a56d6c31c9f822da8d69ab60925a514978c2da3ec63d7c6f1d |
|
MD5 | 87efaa8fec3f71b12090079bdd0d784f |
|
BLAKE2b-256 | bab0e5115584096eb9681e25881ce5e658239b57c9013c99eadd64bf9ab1c016 |