Share
Yes, there is StringIO:
import StringIO import sys sys.stdout = StringIO.StringIO() print "foo", "bar", "baz" s = sys.stdout.getvalue()