Guest User

Maya_win_tee_stdout

a guest
Mar 5th, 2012
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import sys, os
  2.  
  3. class Tee(object):
  4.    
  5.     def __init__(self, filename):
  6.         self.teeFile    = open(filename, "w")
  7.         self.stdout     = sys.__stdout__
  8.         sys.__stdout__  = self
  9.        
  10.     def __del__(self):
  11.         self.restore()
  12.        
  13.     def restore(self):
  14.         sys.__stdout__ = self.stdout
  15.         self.teeFile.close()
  16.  
  17.     def write(self, val):
  18.         self.teeFile.write(val)
  19.         self.stdout.write(val)
  20.         self.teeFile.flush()
  21.  
  22. tee = Tee("c:/log.txt")
Advertisement
Add Comment
Please, Sign In to add comment