我有一个在 Windows 上运行良好的 python3.6.0 脚本。但是当我在 bash 中运行它时,出现语法错误。这是代码:import itertoolslines=["Hamlet","William Shakespeare","Edited Barbara B Mowat Paul Werstine","Michael Poston Rebecca Niles","Folger Shakespeare Library","httpwwwfolgerdigitaltextsorgchapter5playHam","Created Jul 31 2015 FDT version 092","Characters Play","line 17 POLONIUS father Ophelia Laertes councillor King Claudiusthis line substituted GHOST"]LinesMap=dict()for line in lines:list=[l for l in line.split(' ')]d = dict(itertools.zip_longest(*[iter(list)] * 2, fillvalue=None))LinesMap = {**LinesMap, **d}print(LinesMap)这是错误:[reza@localhost ~]$ python New\ Text\ Document.py File "New Text Document.py", line 16LinesMap = {**LinesMap, **d} ^SyntaxError: invalid syntax
2 回答

蛊毒传说
TA贡献1895条经验 获得超3个赞
在许多 Linux 发行版上,python
指的是 Python 2,您需要使用它python3
来运行 Python 3 脚本。
根据您的发行版,您应该能够使用 Python 3yum
或apt-get
一个包,它可以与 Python 2 很好地共存,部分原因是决定为可执行文件使用不同的名称。
更详细地说,apt-get install -y python3
(可能与sudo
或询问您的管理员)应该在基于 Debian 的平台(Mint、Ubuntu,你有什么)上安装 Python 3;并且yum install python36
应该在各种基于 RPM 的平台上安装 Python 3.6(Fedora、CentOS 等,同样可能使用sudo
或类似的东西)。
添加回答
举报
0/150
提交
取消