Jan-06-2019, 01:12 AM
Hello,
I'm extremely new to Python and I was recently given some code for a study I'm working on, however it seems to contain some errors. I was able to fix some of the minor ones, but I'm still unable to get it running all the way through.
I'm currently getting errors regarding how the data file is being written. Posted below is the code leading up to and including the section that's been giving me trouble. Hopefully this is enough context. If I could have any advice on what the issue might be here and on any other errors in this section of the script I'd greatly appreciate it.
Thanks in advance.
I'm extremely new to Python and I was recently given some code for a study I'm working on, however it seems to contain some errors. I was able to fix some of the minor ones, but I'm still unable to get it running all the way through.
I'm currently getting errors regarding how the data file is being written. Posted below is the code leading up to and including the section that's been giving me trouble. Hopefully this is enough context. If I could have any advice on what the issue might be here and on any other errors in this section of the script I'd greatly appreciate it.
Thanks in advance.
from psychopy import visual, gui, core, event import random as random import os #set directory path path=os.getcwd() #set number of trials numtrials=100 #make a GUI to collect participant number COVATDlg=gui.Dlg(title="Covert Orienting Task") COVATDlg.addText('Participant Number', color='black') COVATDlg.addField('Participant ID:') COVATDlg.addField('Age:') COVATDlg.addField('Gender:',choices=['male','female']) COVATDlg.addField('Handedness:',choices=['left','right','both']) COVATDlg.show() if gui.OK: startInfo=COVATDlg.data print('startInfo') else: print('cancelled') #set window screen_size=(1366,768) win=visual.Window(size=screen_size,color=(-1,-1,-1),units='pix',fullscr=True) #initialise data file - refer to 'startInfo' above for participant number dataFile=startInfo[0] dataHeader=["Participant","Age","Gender","Handedness","Trial","Cue Side", "SOA","Target Type","RT"] dataFile.write(",".join(dataHeader) + "\n") dataFile.flush() #Create function to write data def recordData(pt,age,gender,hand,trialnum,cue,soa,val,rt): dataFile.write(",".join([str(pt),str(age),str(gender),str(hand),str(trialnum),str(cue),str(soa),str(val),str(rt)])+"\n") dataFile.flush()