Range object cannot be interpreted as an integer

Hello,

I have been sent the code for a script someone else (years ago) developed in Python but am having issues running the experiment and hoped someone might be able to advise me on how to best proceed/what the error might be as I’m completely lost!

The error type I’m receiving is from line 114, saying: ‘range’ object cannot be interpreted as an integer

That part of the script is here:

I have tried both changing, for example, “range(1, 32)” to “range(len(1, 32))” and doubling the brackets (which has worked in the past and is recommended on many of the discussion boards here) but with no luck.

I also wondered if it was a package issue (something to do with .gui) but I have the most current version of PsychoPy so I wouldn’t have thought that was the case…?

I realise I haven’t given much information to go on but any direction on what to try next would be greatly applicated (I feel like it’s a really simple fix that I just haven’t cracked yet!)

Thank you!

I think that script was written using Python2 and isn’t quite compatible with Python3. Python2 used to return list objects from the range command whereas Python3 doesn’t but you can convert back to the old-school by wrapping your range function in a list function:

'birth_day': list(range(1, 32)),
...

This works perfectly, Jon, thank you so much!
It still caused some minor problems later in the script but these were easily fixed (unlike my attempts above which resulted in a whack-a-mole situation, with errors popping up all over the place)!
I’ll definitely keep this work-around in mind in the future.