The print >> file Extension : redirect « File « Python Tutorial






import sys 
temp = sys.stdout                     
sys.stdout = open('log.txt', 'a')     
print 'spam'                          
print 1, 2, 3 
sys.stdout.close(  )                  
sys.stdout = temp                     

print 'back here'                     
print open('log.txt').read(  )








12.13.redirect
12.13.1.Redirecting the Output Stream
12.13.2.The print >> file Extension