def SetOutputFile(file=None, needclose=0):
 global _File, _NeedClose
 if _NeedClose:
  tmp = _File
  _NeedClose = 0
  _File = None
  tmp.close()
 if (file is None):
  import sys
  file = sys.stdout
 _File = file
 _NeedClose = (file and needclose)

def SetOutputFile ( file = None , needclose = 0 ) : global _File , _NeedClose if _NeedClose : tmp = _File _NeedClose = 0 _File = None tmp . close ( ) if ( file is None ) : import sys file = sys . stdout _File = file _NeedClose = ( file and needclose )
call this with an open file object to make it the output file .