Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

redirect stdout to variable python

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()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #redirect #stdout #variable #python
ADD COMMENT
Topic
Name
3+9 =