【问题标题】:I get a syntax error about File "<stdin>", line 1我收到有关文件“<stdin>”第 1 行的语法错误
【发布时间】:2021-01-09 09:16:47
【问题描述】:

这是错误,我不知道故障在哪里:

> & C:/Users/tanel/AppData/Local/Programs/Python/Python38/python.exe  
"c:/Users/tanel/Documents/Projects/Coding/Python/Game Alien/game.py"
  File "<stdin>", line 1
    & C:/Users/tanel/AppData/Local/Programs/Python/Python38/python.exe "c:/Users/tanel/Documents/Projects/Coding/Python/Game Alien/game.py"
    ^
SyntaxError: invalid syntax

【问题讨论】:

  • Please don't post screenshots of text。它们无法被搜索或复制,并且可用性差。相反,将代码作为文本直接粘贴到您的问题中。如果选择它并单击{} 按钮或Ctrl+K,则代码块将缩进四个空格,这将导致其呈现为代码。

标签: python syntax-error


【解决方案1】:

你得到一个 Python SyntaxError 因为你试图在 Python shell 中运行一个 PowerShell 命令:

>>> & C:/Users/tanel/AppData/Local/Programs/Python/Python38/python.exe "c:/Users/tanel/Documents/Projects/Coding/Python/Game Alien/game.py"

exit 退出该 shell,然后在 PowerShell 中运行您的 PowerShell 命令。提示应该类似于

PS C:\>

Python shell 用于以交互方式运行代码,例如您可以直接在其中输入import pygameprint("Hello, world!") 之类的内容。

【讨论】:

    猜你喜欢
    • 2022-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    • 2019-09-18
    • 2017-09-04
    • 2017-09-28
    相关资源
    最近更新 更多