![]() |
#2
|
|||
|
|||
Hi,
This problem stems from the fact that Vizard runs each script twice. When you first run a script, Vizard parses the script once to check for errors. During this first parse only code in the global scope is executed, code inside functions is not executed. Next, Vizard passes the script off to the graphics engine which parses the script and begins executing code inside functions such as keyboard handlers and timer handlers. What's happening in your case is that the following code is being called twice since it resides in the global scope: Code:
fileOutput = open(hi.txt', 'a') fileOutput.write('hi there\n') Whew, hope that made at least some sense ![]() For now you could do something like the following, but we'll try to come up with a better solution: Code:
import viz viz.go() def mykeyboardfunc(key): global fileOutput if key == 'o': fileOutput = open('hi.txt', 'a') fileOutput.write('hi there\n') if key == 'c': fileOutput.flush() fileOutput.close() print "file should be closed now" viz.callback(viz.KEYBOARD_EVENT, mykeyboardfunc) |
|
|