captures temporarily stdout and stderr
Project description
captures temporarily stdout and stderr
Tested against Windows 10 / Python 3.10 / Anaconda
pip install stderrstdoutcapture
GetStdErr
A context manager that captures and temporarily redirects standard error (stderr) to a list.
Usage:
from stderrstdoutcapture import GetStdErr
def errtest():
try:
x = 5 / 0
except Exception:
return "error"
with GetStdErr() as o2:
returnvalue2 = errtest()
print(o2) # Access captured stderr as a list
print(f"{returnvalue2=}") # Display the return value of the function
Methods:
__enter__(*args, **kwargs): Enter the context and redirect stderr to a StringIO buffer.
__exit__(*args, **kwargs): Exit the context and append the captured stderr to the list.
GetStdOut
A context manager that captures and temporarily redirects standard output (stdout) to a list.
Usage:
from stderrstdoutcapture import GetStdOut
def outtest():
try:
x = 5 / 5
print("five devided by five is one")
return x
except Exception:
pass
with GetStdOut() as o1:
returnvalue1 = outtest()
print(o1) # Access captured stdout as a list
print(f"{returnvalue1=}") # Display the return value of the function
Methods:
__enter__(*args, **kwargs): Enter the context and redirect stdout to a StringIO buffer.
__exit__(*args, **kwargs): Exit the context and append the captured stdout to the list.
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 Distribution
Built Distribution
Close
Hashes for stderrstdoutcapture-0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e37a6a8d4bc392f308866f20ee42fbdb494f63a0397aea7789829f8ace2962f3 |
|
MD5 | 4304379372b5d12ac492dcf3436bd4ab |
|
BLAKE2b-256 | 60c35e633b8a5fb6bfcac2705b2b3c22da403c0eeccb63bf944e8dec5a2d8f35 |