psychopy.org | Reference | Downloads | Github

Syntax error on defining a variable using colon ":"

Hello everyone,
I’m a beginner with psychopy, with the coder more precisely.
I’m taking a course with a pdf support that should be done on psychopy 3.1.5. But this version does not launch on my computer.

So I decided to use version 2021.2.0. Now I am doing an exercise where I have to define variables with colon “:”.
An example of my very simple code:
v1 = list( range( 17))
print ( v1)
v2 = 1:16
print ( v2)
In the output, I have this message :
v2 = 1:16
^
SyntaxError: invalid syntax
Maybe the way to define variables has changed? I’ve already tried that code with older versions and this kind of assignment was not a problem.
Thank you for your help!

This may have been valid in Python2 but it isn’t in Python3 - which PsychoPy runs on. If you’re trying to do the same thing as that notation would in MATLAB, I think what you need is:

range(start=1, stop=16)

If you are setting up a variable for selecting rows in a loop then you can put quotes round it,

e.g. v2="0:16" would select the first 16 items from a spreadsheet.

Hi,
Thank you for answering me!
I assigned v2 with the code you wrote and I got this answer
v2 = range(start=1, stop=16)
TypeError: range() does not take keyword arguments
Do you have another solution?

So the assignment with colon “:” worked python older versions but not in the new one? I tried to install psychopy 3.1.5 on two computers to have the same version as in the ebook course. But it seems that there is a incompatibility problem with the current version of python. I installed python 2.7 and psychopy 3.1.5 ( standalone windows) on one of the pc to see if they match. But psychopy just won’t run.
Thank you for your help!

Hi, thank you for answering me!
I don’t try to create a loop. It’s a basic variable assignment . Thank you for your response!

Ah, I forget it doesn’t take keywords… You should be able to do it with positional arguments:

range(1, 16, 1)

(start at 1, stop at 16, step 1 at a time)

Doesn’t that stop at 15?