I was trying to make something using the function 'Counter' (from collection).
And I got the following error.
File "/home/knut/catkin_ws/src/knut_ai_vehicle_2019/scripts/CameraStatus.py", line 5, in <module>
from collection import Counter
File "/home/knut/.local/lib/python2.7/site-packages/collection/__init__.py", line 1, in <module>
from .Collection import Collection
File "/home/knut/.local/lib/python2.7/site-packages/collection/Collection.py", line 22
def __init__(self, items) -> None:
^
SyntaxError: invalid syntax
This script is in ROS package, and ROS supports only python2 as far I know.(Am I right?)
So I'm using python 2.
I don't know, but... I guess this is an issue that comes from Python 2 no longer being updated.
Actually, I've never seen that arrow function before.
I kept looking, but I couldn't figure out why that arrow was causing a problem.
the Only I did is to install 'collection' using pip and import it.
I want anyone who has encountered this error to help me.
The ->
is what's called a function annotation. Function annotations are somewhat relatable to how python 2.x had docstrings. They allow you to attach metadata to a function and in this specific case the ->
is an annotation for the function return type. You can do some more complete reading about annotations here.
The issue you're having is coming from the fact that annotations are a 3.x feature and thus it is invalid syntax in 2.x. As for your point of needing python 2.x for ROS, this isn't true. ROS Noetic supports Python3 and since it's the newest stable release, I'd suggest using that distro.