Creating stimuli by random selection from a file: Problem solved

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): PsychoPy 2021.1.2
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:
I want to select items from a shuffled list of words, using the conditions file to indicate which position in
the list to take an item from. I am doing this as a way of having a random selection of items go into
fixed roles in a discrimination learning task.
I started from the fact that I can put words in a conditions file, with headers of “stim1” and “stim2”
and have words in the columns, like this:
Then if I use code of “display = $stim1 + $stim2”, I will get a display that shows, for example, “cat strawberry”

I have used code to read a file and create a list of words, and I can select an item in the list using code
like the following: item=lista[1]

What I want is to be able to insert a number for “1” in this example. What I have done is to put the numbers I want to use in the condition file, with headers of stim1, stim2, like this:
so that $stim1 can be not a number but word #1 in lista or word #11 in lista.
I tried the following
but get a syntax error.
SyntaxError: invalid syntax

What did you try to make it work?:

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

The dollar sign denotes variables in PHP but not Python or JavaScript. PsychoPy uses it in components (not code components) to show that the following text should be interpreted as code rather than text.

Try itmloc1=stim1 or itmloc1=int(stim1)

Thanks! I realized I had made other errors of understanding in the process as well, and now I have it working, with your suggestion included. Does PsychoPy 2021 still use the xlrd module? I have read that it doesn’t but seen an example where it seems to be in use. (Obviously, I can try it and find out, which I will do).