Answers for "redirect stdout to variable python"

0

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()
Posted by: Guest on June-02-2020

Python Answers by Framework

Browse Popular Code Answers by Language