psychopy.org | Reference | Downloads | Github

How to deal with python dictionaries in online experiments?

Hello all,

I currently have an experiment created in builder on my local machine, which I will soon be trying to move online. As far as I understand, the code elements will be translated to JS when I move online, so I am carefully watching the Auto–> JS window of each code element.

When I initialized a dictionary to keep track of my experiment conditions, e.g.:

# create dictionaries for condition effects
conditionRecall = {k:[] for k in pitchTypes}

… I got /* Syntax Error: Fix Python Code*/ in the JS side. However, the experiment runs normally and the dictionary seems to be working fine on my local machine.

Does the syntax error mean that I will have problems when trying to go online? Is there anything I can change? Thanks in advance

Hi @aisa2, this will be because the autotranslate is not handling your dict comprehension, so you will have to instead use the long form to create your dict:

conditionRecall = {}
for k in pitchTypes:
    conditionRecall[k] = []

@dvbridges thank you!

@dvbridges does this mean that any comprehension (list, dict, etc) will not translate well?

@aisa2, I just added some list comprehension to a code component, and it translated ok.

1 Like