这个简单的 Python 列表的语法有什么问题?

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

也许我对 Python 生疏了。为什么粘贴到 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"
    ]

当它被复制到 xterm 运行 python3 中的提示时,我得到(不要介意古朴的复古术语):

编辑:我真傻,忘了报告一些基本的明显信息:这是 Python 版本 3.9.1,在 Arch Linux 上大约一个月前更新。

所以,我在这里没有 完整 答案,但这与新的 PEG 解析器有些东西有关that debuted in Python 3.9,因为当我使用它时(它是 Python 3.9 上的默认解析器),我得到同样的错误:

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

但是您可以通过传递命令行选项恢复到旧的 LL(1) 解析器,瞧!没有错误:

(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()

对于那些感兴趣的人,PEP 617 关于新解析器的相关内容。

编辑

因此,这似乎不再是 Python 3.9.2(我相信是当前最新版本)的问题。那么也许升级?

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"
...     ]
>>>

是的,也许只需要升级,我也遇到过 运行 这个问题,我的问题是解释器错误,教程已解决 这是 link 也许它会像帮助我一样帮助你: https://youtu.be/RvbUqf3Tb1s 修复