What is wrong with the syntax of this simple Python list?

Viewed 279

Maybe I've gotten rusty with Python. Why is this not acceptable when pasted into a Python shell?

hdr_filenames = [
    "20210311_105300_HDR.jpg",
    "20210311_105306_HDR.jpg",
    "20210311_105310_HDR.jpg",
    "20210311_105314_HDR.jpg",
    "20210311_105341_HDR.jpg",    # order of last two have reversed exposures   
    "20210311_105323_HDR.jpg"
    ]

When this is copied to the prompt in an xterm running python3, I get (never mind the quaint retro term):

enter image description here

EDIT: silly of me to forget to report some basic obvious info: This is Python version 3.9.1, on Arch Linux updated about a month or so ago.

2 Answers

So, I don't have a complete answer here, but this has something to do with the new PEG parser that debuted in Python 3.9, because when I use it (it is the default parser on Python 3.9), I get the same error:

Python 3.9.1 (default, Dec 11 2020, 06:28:49)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> hdr_filenames = [
    "20210311_105300_HDR.jpg",
    "20210311_105306_HDR.jpg",
    "20210311_105310_HDR.jpg",
    "20210311_105314_HDR.jpg",
    "20210311_105341_HDR.jpg",    # order of last two have reversed exposures
    "20210311_105323_HDR.jpg"
    ]
  File "<stdin>", line 1
        ]
         ^
SyntaxError: multiple statements found while compiling a single statement

BUT You can revert to the old, LL(1) parser by passing a command line option, an voila! No error:

(py39) juanarrivillaga@50-254-139-253-static % python -X oldparser
Python 3.9.1 (default, Dec 11 2020, 06:28:49)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> hdr_filenames = [
    "20210311_105300_HDR.jpg",
    "20210311_105306_HDR.jpg",
    "20210311_105310_HDR.jpg",
    "20210311_105314_HDR.jpg",
    "20210311_105341_HDR.jpg",    # order of last two have reversed exposures
    "20210311_105323_HDR.jpg"
    ]
>>> exit()

For those interested, the relevant PEP 617 about the new parser.

EDIT

So, this no-longer seems to be a problem on Python 3.9.2 (the latest version currently, I believe). So perhaps upgrade?

Python 3.9.2 (default, Mar  3 2021, 11:58:52)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> hdr_filenames = [
...     "20210311_105300_HDR.jpg",
...     "20210311_105306_HDR.jpg",
...     "20210311_105310_HDR.jpg",
...     "20210311_105314_HDR.jpg",
...     "20210311_105341_HDR.jpg",    # order of last two have reversed exposures
...     "20210311_105323_HDR.jpg"
...     ]
>>>

yes maybe just needs an upgrade, I have ran into this problems too for me the problem was the interpreter was wrong and tutorial solved here's the link maybe it will help you as well as it did helped me: https://youtu.be/RvbUqf3Tb1s The Fix

Related