#1
|
|||
|
|||
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. |
#2
|
|||
|
|||
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.
|
#3
|
|||
|
|||
Thank you, that helped greatly.
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Closing of an imported .py file | Uttama_vizard | Vizard | 2 | 05-04-2010 06:18 AM |
IVEx file extenstion unrecognised. | sindi | Vizard | 2 | 12-10-2009 01:20 AM |
Read file....many issues | Uttama_vizard | Vizard | 9 | 07-08-2008 02:16 PM |
File Management | Uttama_vizard | Vizard | 2 | 07-01-2008 09:44 AM |
Closing file handles from within function | FlyingWren | Vizard | 1 | 10-01-2003 06:02 PM |