psychopy.org | Reference | Downloads | Github

Loading and writing files while running experiment

URL of experiment: https://pavlovia.org/petab/tokendebug

Description of the problem:

Hey all,

so I was wondering if anyone needed to load and write files during experiment. I’ve seen quite a recent post with similar topic, here - https://discourse.psychopy.org/t/experiment-not-saving-data-online-generates-empty-csv-files/8174

and there it seems that it’s not possible right now. It’s quite easy to make it with python code, by importing csv module or even using TrialHandler. My problem is when it comes to online javascript adaptation. After some reading, it seems like non-trivial problem.

My goal is to use a csv file as a counter and everytime the experiment runs, the number in csv increases by 1. The file is then saved and overwriten with next run, so it contains always the last saved number.

Here is some idea with python script:

So this would be in begin experiment tab:

counterW = 0

and for the begin routine:

counterW = counter              ## load content of the file into new variable
counterW = counterW + 1         ## increasing by 1
import csv
with open('counter.csv', 'w') as csvfile:
    writerC=csv.writer(csvfile, lineterminator='\n')
    writerC.writerow(['counter'])        ## write row with header 'counter'
    writerC.writerow([counterW])         ## add increased number to second row

The file is loaded in the loop and I’m accessing its content by simply using ‘counter’ variable used as a header in the file.

That’s obviously not working with javascript. Does anyone have an idea how to do something similar in javascript ?
I’m already quite skeptical about that, but it would be great to have a solution to it.

Btw. the experiment is just for this fix, it’s not working and does not have any content.

Thank you very much!

I don’t believe creating such a counter file is possible, which is why I am using Qualtrics before and/or after the PsychoPy experiment for assigning to conditions, demographics, etc.

Ah right, thank you for your reply, I read your reaction also for the other post. I have similar feeling, but was thinking that maybe there was some progress on it. But again, thank you!

When there’s a new version I’ll try to highlight any changes in my crib sheet

Great, thank you very much, also for your suggestion with Qualtrics, I’ll definitely explore and give it a try.