WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Help with File Reading/Writing (https://forum.worldviz.com/showthread.php?t=4151)

Lynnifer 02-27-2012 12:33 PM

Help with File Reading/Writing
 
I am new to Vizard and Python, and I am having difficulty modifying a program used by a previous member of my lab for a new experiment I need to run. Specifically, I am getting an error that says:


File "", line 12, in ?
File "Jen_OpFlow1_exp.py", line 408, in ?
tracking_data = open('Prism_VE Data_Dual Distortion_No Maze or Letters/headdata_'+ str(Subnum) + '.txt', 'a')
IOError: [Errno 2] No such file or directory: 'Prism_VE Data_Dual Distortion_No Maze or Letters/headdata_999.txt'


I believe this is the relevant section of code for the error:



tracking_data = open('Prism_VE Data_Dual Distortion_No Maze or Letters/headdata_'+ str(Subnum) + '.txt', 'a')
tracking_data2 = open('Prism_VE Data_Dual Distortion_No Maze or Letters/handdata_'+ str(Subnum) + '.txt', 'a')
#tracking_data3 = open('Prism_VE Data_Dual Distortion_No Maze or Letters/kneedata_'+ str(Subnum) + '.txt', 'a')
#tracking_data4 = open('Prism_VE Data_Dual Distortion_No Maze or Letters/ankledata_'+ str(Subnum) + '.txt', 'a')
#"""

flags = ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']
flagIndex = 0
def WriteFlag():
global flags, flagIndex
try:
letter = flags[flagIndex]
flagIndex = flagIndex + 1
tracking_data.write('*** Reached point ' + letter + '\n' + "*** Elapsed time =" + str( clock() - starttime) + " seconds \n")
tracking_data2.write('*** Reached point ' + letter + '\n'+ "*** Elapsed time =" + str( clock() - starttime) + " seconds \n")
tracking_data3.write('*** Reached point ' + letter + '\n'+ "*** Elapsed time =" + str( clock() - starttime) + " seconds \n")
tracking_data4.write('*** Reached point ' + letter + '\n'+ "*** Elapsed time =" + str( clock() - starttime) + " seconds \n")
print '*** Reached point ' + letter + '\n'+ "*** Elapsed time =" + str( clock() - starttime) + " seconds \n"
except IndexError:
print "Stop pressing 'f', you're out of flags"
vizact.onkeydown('f',WriteFlag)


What I need it to do is create and write the data to the file if it does not exist already, or to open and append to the file if it does already exist. Any advice would be greatly appreciated.

farshizzo 03-02-2012 04:14 PM

My guess is that the folder Prism_VE Data_Dual Distortion_No Maze or Letters does not exist in the same folder as your script. Try creating the folder then running the script again.

Lynnifer 03-12-2012 06:51 AM

Thank you, that helped greatly.


All times are GMT -7. The time now is 11:41 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC