Predefined string variables in the excel file for indicating different conditions (image files)

macOS Mojave 10.14.6
Psychopy v3.2.3

Hi, I am trying to create an excel file to indicate different image conditions while randomly allocating image files to different conditions across participants (randomly assigning different shapes to conditions).

My image file names are shapes/circle.png, shapes/cross.png… and so on. So I randomly shuffled them as a code like this at the beginning of the experiment in the builder:

In this case, how should I name them in the excel file where conditions are indicated. Certainly, this does not work because it only recognises shapeLeft and shapeRight variables as strings not string variables:

Thanks a lot for your help in advance!

Hyunji

Hi Hyunji,

You need to tell Python to evaluate the string variable as Python code, so instead of referring to shapeLeft directly, use eval(shapeLeft) instead.

One of Python’s superpowers!

1 Like

Hi Micheal, thanks so much for your help! I really wished that it would have worked right away but something is missing and I want to make sure I did it in the right way.

I did (after adding import math as a code):

then the error msg was:

then, I tried eval(‘shapeLeft’), eval($shapeLeft), $eval(shapeLeft) and was not successful.
What do you think I am missing here?

Thanks again for your assistance!

Hyunji

It should be $eval(shapeLeft) to indicate this expression is also code, and shouldn’t be treated as a literal filename.

Can you please show us the error that arises from using that expression (it should be different)?

1 Like

Dear Michael,

It worked now! Because the error I had with $eval(shapeLeft) was this:

And I noticed that this error shows up after a couple of trials so realised that I had empty slots in the excel file where I did not want to show any images (empty screen). So after filling that out with an image similar to the background color, it is working fine. Thanks a lot! :-))

Although it is tricky to get that background color exactly. Is there another way around to make it an empty image?

Thanks a bunch!

Hyunji

So, putting “None” instead of an empty cell in the excel file worked! :))
Thanks so much!

Hyunji