1def print_to_stdout(a, b): 2 """ 3 >>> print_to_stdout(1, 'test') 4 <BLANKLINE> 5 1 6 1 test 7 1 test 8 1 test 42 spam 9 """ 10 print 11 print a 12 print a, 13 print b 14 print a, b 15 print a, b, 16 print 42, u"spam" 17 18 19try: 20 from StringIO import StringIO 21except ImportError: 22 from io import StringIO 23 24def print_to_stringio(stream, a, b): 25 """ 26 >>> stream = StringIO() 27 >>> print_to_stringio(stream, 1, 'test') 28 >>> print(stream.getvalue()) 29 <BLANKLINE> 30 1 31 1 test 32 1 test 33 1 test 42 spam 34 <BLANKLINE> 35 """ 36 print >> stream 37 print >> stream, a 38 print >> stream, a, 39 print >> stream, b 40 print >> stream, a, b 41 print >> stream, a, b, 42 print >> stream, 42, u"spam" 43