View Single Post
  #1  
Old 10-01-2003, 05:10 PM
FlyingWren FlyingWren is offline
Member
 
Join Date: Mar 2003
Location: Fargo, North Dakota, USA
Posts: 48
Closing file handles from within function

Closing file handles works fine if I don't do it from within a function call.

Consider the following, though. I press a key, and the "file should be closed now" line appears. But, the file doesn't seem to close-- it can't be renamed or deleted without first exiting the program that created it (ie, Vizard).

am I missing something?

Code:

import viz
viz.go()

fileOutput = open(hi.txt', 'a')
fileOutput.write('hi there\n')

def mykeyboardfunc(key):
	fileOutput.flush()
	fileOutput.close()
	print "file should be closed now"
	
viz.callback(viz.KEYBOARD_EVENT, mykeyboardfunc)
Reply With Quote