fptr = sys.stdout # stdout is already an open stream #or os.environ['OUTPUT_PATH'] = 'junk.txt' # before you open the fptr!