expInfo is not defined?

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

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): 3.1.0
Standard Standalone? (y/n) yes
**What are you trying to achieve?: I am trying to present different stimuli based on participant info entered into the experiment info dialogue box.



What specifically went wrong when you tried that?:
NameError: name “expoInfo” is not defined

Hi @chanws, the error is because PsychoPy is evaluating the contents of your conditions file before the experiment is run in order to create your trials. So, at this point, the expInfo dictionary does not exist. You would be better off changing the conditions file depending on the content of your expInfo fields. E…g, in your loop, you would create a path like this:

$'order' + expInfo['condition'] + 'xlsx'

Thanks @dvbridges! This makes a lot of sense. But is there a way for to change the image stimuli depending on the expInfo content? If I can’t do that, I’ll have to create hundreds of excel files for different combinations of stimuli…

I’m not sure that is normally the case: Builder actually passes the expInfo dictionary to each TrialHandler on creation, as its extraInfo parameter. So expInfo should normally be there when needed.

Your error message reads:

Did you cut and paste that verbatim? Because it contains a typo for expInfo. Is it possible that somewhere else you are referring to this variable incorrectly? (It is spelled correctly in your conditions file.)

Thanks @Michael. I did not cut and paste the error message. I just typed it out, so I had a typo there. There isn’t a typo in the code though. I think I just figured out a way to do it. I could just type $‘order’ + expInfo[‘condition’] + ‘.jpg’ into the loop to link to different image stimuli…

Well…I took that back. I don’t think I found a way to do exactly what I wanted yet. Each condition is going to present a combination of image stimuli. If I link directly to one image, then it won’t let me loop through a combination of stimuli. The problem is that whenever I put this:
$'order' + expInfo['condition'] + '.jpg'
in the excel file, the error comes up, either it reads it as a string, or it says expInfo is not defined.

To make it clearer…

When I put a specific excel file in Conditions in the loop, and in the excel file I put
$'images/' + expInfo['lowpalcon']+'.jpg'
$'images/' + expInfo['highpalcon']+'.jpg'
to try to present different sets of image stimuli for different conditions

The error messages I got was this:


suggesting that code wasn’t read properly

I changed it to
‘’’ [‘images/’+expInfo[‘lowpalcon’]+’.jpg’] ```

Then it seems to read it properly, but it says expInfo is not defined

You’re right @Michael. I think the eval arg is being evaluated in the scope of the psychopy library. So, expInfo is not found because it is not
in the PsychoPy lib namespace.

Wow, you’re right, this is a tricky one to nail down. I guess the problem might be having the eval statements inside the Excel file data, but that seems surprising that they would get evaluated rather than just treated as strings at that stage.

@chanws: The error message seems to have changed over time (which is why the expInfo error no longer occurs. It now looks like the filename expression is just being interpreted as a literal string rather than being evaluated. This could be the case if:

  • the $ sign has migrated from being in the file name field to being the in Excel sheet.
  • since there doesn’t seem to be an eval() function embedded in the string anymore (presumably it has been dropped from the Excel cells), then perhaps it now belongs in the filename field, e.g.
$eval(pavfoodimage)

which would stop any evaluation happening at the Excel file import stage.