Looping through python variables in conditions file

OS (e.g. Win10): macOS 15
PsychoPy version (e.g. 2024.2.4 Py 3.8): v2025.1.1
Standard Standalone Installation? (y/n) If not then what?:
Do you want it to also run online? (y/n) y

What are you trying to achieve?:

Early in my experiment, I determine certain variables that are used throughout for each participant. For example “image_v” is a variable that points to the path of an image in my resources folder.

Later, I want to loop through some of these image variables using a conditions file but I can’t find a way to do this. In my file, I have a column “added_image” with a list of variables which should refer to images. In my image component in the builder I refer to this column in the usual way “$added_image”. Instead of inserting the variable path as the image, it instead searches for “image_v” in my resources folder.

What did you try to make it work?:

I’ve tried a few things, such as putting $ in front of the variables in the file, expInfo[image_v] (with and without quoatations), converting to literal (literal_eval(image_v)), but no luck. In all cases I get the error “OSError: Couldn’t find image literal_eval(replacement_food); check path? (tried: /Users/x/Library/CloudStorage/OneDrive/Tasks/PIT_food_v1/image_v).

I can manually code this loop in using the custom coder, but it would be handy to be able to use a conditions file instead.

You’ll need to either do something simple, like:

thisImage = ''
if added_image == 'image_v':
     thisImage = image_v
elif added_image == ...

alternatively you might be able to set up a dictionary where

all_images = {'image_v': 'path/to/image_v.png', etc }

then you could use $all_images[added_image] in your image component.