Created
March 9, 2012 08:29
-
-
Save aar0u/2005647 to your computer and use it in GitHub Desktop.
Python: print to buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://stackoverflow.com/questions/1218933/can-i-redirect-the-stdout-in-python-into-some-sort-of-string-buffer | |
from cStringIO import StringIO | |
import sys | |
old_stdout = sys.stdout | |
sys.stdout = mystdout = StringIO() | |
# blah blah lots of code ... | |
sys.stdout = old_stdout | |
# examine mystdout.getvalue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment