Writing to external file with python inline script
Hello everyone,
here I have a question that I could not solve on my own. In our visual search experiment we create a random array of 300 letters with an inline script in Open Sesame. I would like the pixel position of each letter to be saved in an external file for later comparison with eye tracker data. We got this to work in psychopy with the following code:
df = open(("data_" + participant+ ".txt"),'a')
df.write(participant + "\t" + str(i) + "\t" + str(letterChoice) + "\t" + str(randX) + "\t" + str(randY) + "\n")
df.close()
This opens a dataframe, names it with the participant number and then writes participant number, letter-number (i=1-300), the random letter determined further up in the script (letterChoice), and the random x and y coordinate (randX/Y) of each of those 300 letters.
It then closes the data file, until it reopens it in the next trial, where the same happens again.
So for each trial in psychpy we end up having 300 lines in the created .txt file with the correct info stored in an external file.
I transferred the code to Open Sesame but there nothing happens. The processing time goes up a little compared to without the write-to-file- code, but it does not create that file! There also is no error message. The experiment finishes correctly, but alas, I don't get the data file.
Would anyone have an idea how to accomplish Open Sesame writing these letter coordinates to a file separate from the log file?
Best,
Titus
Comments
Hi Titus,
Since OpenSesame is python-based, things such as writing data to a file should work in a manner similar to how it's done in a regular python environment. Might it help to include the full path when initiating your df file?
Cheers
Josh
Thanks for the quick reply Josh, that did it! pretty easy fix:
It writes the data file and everything inside looks fine.
Cheers
Titus