也许我已经对 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 中的提示时,我得到(更不用说古怪的复古术语):编辑:忘记报告一些基本的明显信息我很傻:这是 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/