Extended Print StatementNew syntax for printing to filef = open("foo","w") print >>f, "Hello World" for i in range(10): print >>f, "i = ",i f.close() Previously, print only printed to sys.stdoutoldstdout = sys.stdout sys.stdout = open("foo","w") print "Hello World" for i in range(10): print "i = ",i sys.stdout.close() sys.stdout = oldstdout Any file-like object can be used
|
<<< | O'Reilly OSCON 2001, New Features in Python 2, Slide 32 July 26, 2001, beazley@cs.uchicago.edu |
>>> |