Skip to content

Instantly share code, notes, and snippets.

@aar0u
Created March 9, 2012 08:29
Show Gist options
  • Save aar0u/2005647 to your computer and use it in GitHub Desktop.
Save aar0u/2005647 to your computer and use it in GitHub Desktop.
Python: print to buffer
#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