WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Error in file opening Vizard (https://forum.worldviz.com/showthread.php?t=6084)

Vishav 12-05-2017 07:13 AM

Error in file opening Vizard
 
Dear all,

I am getting this error in my code when i am opening file in append mode:

Traceback (most recent call last):
File "C:\Program Files\WorldViz\Vizard5\python\viztask.py", line 752, in updateAndKillOnException
return self.update()
File "C:\Program Files\WorldViz\Vizard5\python\viztask.py", line 719, in update
val = self._stack[-1].send(sendData)
File "DFI_Snacks.py", line 50, in task1
IOError: [Errno 22] invalid mode ('a') or filename: '_experiment_data.txt'

My Source Code:


global experiment_data
os.chdir(r'D:\PhD\Study-I_Part_I\My_Programs\DFI\Participant_Data')
filename=str(id) +'_experiment_data.txt'
experiment_data = open(filename,'a')
print str(id)
I am getting exporting id value from other code

Please help me in it.
Thanks

Jeff 12-06-2017 12:33 AM

It looks like the file is not found. Does the following work?

Code:

directory = r'D:\PhD\Study-I_Part_I\My_Programs\DFI\Participant_Data'
filename = str(id) + '_experiment_data.txt'
filepath = os.path.join(directory, filename)
experiment_data = open(filepath,'a')


Vishav 12-06-2017 06:48 AM

Same error is coming with code suggested by you.

I will explain it
I have one file called Parent in which i created file experiment_data having write mode using code.

os.chdir(r'D:\PhD\Study-I_Part_I\My_Programs\DFI\Participant_Data')
experiment_data = open(str(id) + '_experiment_data.txt','w')
data = " Participant ID: %s\tParticipant Name: %s\tAge: %s\tGender: %s\n\n" % (id,Name,Age,gender)
experiment_data.write(data)

After that i made a child code to which i passed id variable value to child using code
id=id
myVars = {'id':id}
exec(open('DFI_Snacks.py').read(), myVars)

Then I open experiment_data file in child code matching with id value in append mode using code

os.chdir(r'D:\PhD\Study-I_Part_I\My_Programs\DFI\Participant_Data')
filename=str(id) +'_experiment_data.txt'
experiment_data = open(filename,'a')

This error is coming when Parent code import child code. I don't know where i am going wrong.

Vishav 12-06-2017 11:09 AM

File Handling
 
1 Attachment(s)
If i open file every time i need to write data then this error not comes but then new problem came that is infobox.remove() is not working. Adding snapshot for reference.
Source Code:
if radio1.get() == viz.DOWN:
infoBox.remove()
score=0

os.chdir(r'D:\PhD\Study-Attachment 964I_Part_I\My_Programs\DFI\Participant_Data')

experiment_data = open(str(id) + '_experiment_data.txt','a')

feedback = viz.addText('You are doing Great!',viz.SCREEN)

Vishav 12-07-2017 09:53 PM

I figured it out... Thanks


All times are GMT -7. The time now is 01:00 PM.

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