from cStringIO import StringIO # Python3 use: from io import StringIO
import sys
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
# blah blah lots of code ...
sys.stdout = old_stdout
# examine mystdout.getvalue()
More Related Contents:
- Temporarily Redirect stdout/stderr
- How do I check if stdin has some data?
- Disable output buffering
- Setting the correct encoding when piping stdout in Python
- Python Requests library redirect new url
- Capture stdout from a script?
- How to open every file in a folder
- Interactive input/output using Python
- Why is printing to stdout so slow? Can it be sped up?
- How to disable logging on the standard error stream?
- Intercepting stdout of a subprocess while it is running
- Multiple inputs and outputs in python subprocess communicate
- Django return redirect() with parameters
- Make a POST request while redirecting in flask
- How do I get ‘real-time’ information back from a subprocess.Popen in python (2.5)
- Python 2.x – Write binary output to stdout?
- Running an interactive command from within Python
- Command executed with Paramiko does not produce any output
- Cannot redirect output when I run Python script on Windows using just script’s name
- Running powershell script within python script, how to make python print the powershell output while it is running
- Can you “stream” images to ffmpeg to construct a video, instead of saving them to disk?
- How to replicate tee behavior in Python when using subprocess?
- Redirecting stdio from a command in os.system() in Python
- How can I redirect print output of a function in python [duplicate]
- Force another program’s standard output to be unbuffered using Python
- How to redirect from one domain to another and set cookies or headers for the other domain?
- How to read the first byte of a subprocess’s stdout and then discard the rest in Python?
- How to redirect from a view to another view In Django
- multiprocessing: How can I ʀᴇʟɪᴀʙʟʏ redirect stdout from a child process?
- Redirect Python ‘print’ output to Logger