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

标签 python python-3.x python-3.9

也许我已经对 Python 生疏了。为什么在粘贴到 Python shell 时这是 Not Acceptable ?

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"
    ]
当将其复制到运行 python3 的 xterm 中的提示时,我得到(更不用说古怪的复古术语):
enter image description here
编辑:忘记报告一些基本的明显信息我很傻:这是 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"
...     ]
>>>

关于python - 这个简单的 Python 列表的语法有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66596113/

相关文章:

python - 错误: [Errno 13] Permission denied: './configure' when use pip3 install matplotlib on termux

python - 在 Windows 上获取本地时区名称(Python 3.9 zoneinfo)

Python 版本 <= 3.9 : Calling class staticmethod within the class body?

python - Python 编程中的列表理解

python - 正则表达式:如果单词 B 在 A 之前的某个位置,如何不匹配单词 A

python-3.x - brew install 没有链接python3

Python:将字典列表转换为列表列表

Python,函数改变值

python - 自定义渲染器破坏站点

python - 将列表转换为元组,然后将此元组添加到 python 列表中