这个简单的Python列表的语法有什么问题?
也许我已经对 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"
]
当将其复制到运行 python3 的 xterm 中的提示时,我得到(更不用说古怪的复古术语):
编辑:忘记报告一些基本的明显信息我很傻:这是 Python 3.9.1 版,在大约一个月前更新的 Arch Linux 上。
回答
所以,我没有一个完整这里的答案,但是这有什么做的新的PEG解析器首次推出在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"
... ]
>>>
- Wow. Dude. That's some killer sleuthing. I'm impressed with your knowledge. I'm clueless as to PEG vs LL(1) vs paper-and-pencil. Most excellent. - In fact...I'd call this a pretty darn complete answer. I think it's unreasonable to expect you to find the exact line of code that is to blame, LOL. What else can you do?
- Your error slightly differs from the OP's screenshot, where there's an empty line above the line with `^`.