Why I always receive the "syntax error" as the texts show? Thx

user:~$ rc = RobotControl()
bash: syntax error near unexpected token (' user:~$ user:~$ l = rc.get_laser_full() bash: syntax error near unexpected token (’
user:~$
user:~$ print ("Position 0: ", l[0])
bash: syntax error near unexpected token "Position 0: ",' user:~$ print ("Position 360: ", l[360]) bash: syntax error near unexpected token "Position 360: ",’
user:~$ print ("Position 719: ", l[719])

Hi @TZ1,

you are writing Python code in the terminal (Bash interpreter).

You should instead paste this code into a file that has the .py extension.

In the instructions you should have seen the file name to be created, for example: my_file.py.

Please let us know if you still have any questions.

Also, double-check the instructions to make sure you are not missing anything.

#KeepPushingYourROSLearning

Thank you, how to execute the code after then?

I receive such errors when execute.

user:~$ python input.py
python: can’t open file ‘input.py’: [Errno 2] No such file or directory
user:~$

Hi @TZ1,

you have to run the python command on the same directory where the input.py file is located.

If the file is on ~/catkin_ws/src, for example, you first have to navigate to that directory:

Example:

cd ~/catkin_ws/src
ls 
python input.py

If you don’t understand the cd command, then you may need to have a look at the free Linux course first, available on The Construct:

Thank you ralves, I’m a newbie. :lion:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.