-2

When I am trying to run an example of pychromecast library, I get the following failure:

~/pychromecast $ python example.py 
Traceback (most recent call last):
File "example.py", line 11, in <module>
import pychromecast.controllers.youtube as youtube
File "/home/pi/pychromecast/pychromecast/controllers/youtube.py", line 27
REQUEST_PARAMS_SET_PLAYLIST = {**BASE_REQUEST_PARAMS, **SET_PLAYLIST_METHOD}
                                ^
SyntaxError: invalid syntax

I've tried running this in both Python2 and Python3. What is wrong here?

3
  • 2
    Link to offending line: github.com/ur1katz/pychromecast/blob/master/pychromecast/… Commented Feb 23, 2017 at 15:56
  • This means that the library only supports modern Python. {**BASE_REQUEST_PARAMS, **SET_PLAYLIST_METHOD} works in Python 3.5 and above. Commented Feb 23, 2017 at 15:58
  • Thanks! That explains it, I've got Python 3.4.5 Commented Feb 23, 2017 at 16:02

1 Answer 1

3

This syntax was released with Python 3.5 as the part of PEP 448 - Additional Unpacking Generalizations.

As per the document: since Python 3.5, tuple, list, set, and dictionary displays allow multiple unpackings like:

>>> *range(4), 4
(0, 1, 2, 3, 4)

>>> [*range(4), 4]
[0, 1, 2, 3, 4]

>>> {*range(4), 4, *(5, 6, 7)}
{0, 1, 2, 3, 4, 5, 6, 7}

>>> {'x': 1, **{'y': 2}}
{'x': 1, 'y': 2}
Sign up to request clarification or add additional context in comments.

1 Comment

{*..., *...} would create a set, but {**..., **...} creates a dictionary.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.