Python error on previously working opensesame experiment when using Anaconda environment
OpenSesame version - 4.0.37
Operating system - Windows 11
Backend - legacy
I have an opensesame experiment I am using to run an eye tracking experiment which has previously worked on Windows (not sure if 10 or 11 sadly). I have had to change eye trackers (from my pilot study) from iMotions to Tobii and therefore have had to change my Opensesame experiment to include PyGaze.
I have created an Anaconda environment following the directions on the Opensesame site using Python 3.10 and Opensesame version 4.0.37.
I was previously using Opensesame version 3.3.14 and Python 3.12.
The python code I am having problems with is:
var.list_locations = ["upper_left", "upper_right", "lower_left", "lower_right"]
var.possible_grid_locations = var.list_locations.copy()
When I try to run the experiment now (on Windows 11, Python 3.10, Opensesame 4.0.37 through Anaconda environment) I get the following error message:
AttributeErrorr: 'str' object has no attribute 'copy'
I am not sure why it won't allow me to copy the list as I believe I have created a list and not a string. I would greatly appreciate if someone can help me figure out how to solve this problem.
Thanks.
Comments
Hi @gel1428
My first guess is that this issue is happening because even though you're assigning a list to var.list_locations, OpenSesame stores it as a string representation of that list. A couple suggestions to fix it:
1) You could convert the string back into a list using ast.literal_eval, like this:
2) Or, you could just work with regular Python variables:
Either way should work, depending on how you’re planning to use the variables.
Hope this helps!
Claire
Check out SigmundAI.eu for our OpenSesame AI assistant! 🤖
Hi Claire,
Thank you very much for that!
Using both methods does fix the error. However, if I use solution one then the variables are not listed in the variable inspector and are not logged. What might be the reason for this?
Thanks!
Hi @gel1428
Glad it's working now!
When using solution one, make sure that you have a line right before it that defines var.list_locations. If you have already done that, check that your logger item is placed after your inline script and that you have either selected 'Log all variables' or entered your variable names manually.
If you're still having issues, you could send me your experiment file so I can take a look.
Cheers,
Claire
Check out SigmundAI.eu for our OpenSesame AI assistant! 🤖
Hi Claire,
I managed to get the variables logged in the end but specifically mentioning them in the logger.
Thanks for all the help!!