| Reference | Downloads | Github

Setting image location from a csv file

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 3.01

Hi there,

I am trying to use the builder modeof the psychoPy. I want to display 6 images at once and have a big csv file with all the x y coordinate of each image. (The column head looks like [img, locx, locy, img1, loc1x,…loc5y]). However, when I try to put this information into the image property, PsychoPy gives me the following error message:

I have tried putting bracket or parenthesis around $locx,$locy, as well as leaving them alone, but all of them give me the similar error.
I am also quite sure the file is set up correctly, because when I put in any numeric number for the position (e.g.(0,0)), all the images will appear with no problem.

Thank you very much for the help!

The $ symbol is not valid Python syntax. It is just a prefix that Builder itself sometimes needs to use, to indicate that what follows should be evaluated as Python code, rather that be taken as a literal value. (e.g. in a text field, locx would display the literal string of four letters locx, whereas $locx would display the actual current content of the variable locx (in this case, the text representation of a number).

You’ll see that the Position field of an image stimulus component already has a $ symbol next to it, so you don’t even need to be use one in this situation (because the content of this field should always be a valid Python expression). So simply put this in the Position field:

[locx, locy]

and set the field to update on every routine.

There is no need to use img.setPos(). The image component already knows what its own name is, and that the expression in this field should be passed to its setPos() function.

1 Like

Great! It works now! I guess I assumed we need to add “$” in front of all variables!!

Thank you!!