View Single Post
  #1  
Old 02-27-2012, 12:33 PM
Lynnifer Lynnifer is offline
Member
 
Join Date: Feb 2012
Posts: 4
Question 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 "<string>", 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.
Reply With Quote