【问题标题】:I get a syntax error about File "<stdin>", line 1我收到关于文件 \"<stdin>\" 第 1 行的语法错误
【发布时间】:2022-12-27 16:33:10
【问题描述】:

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

> & 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!") 的内容。

【讨论】:

    【解决方案2】:

    要解决此错误,只需在您的终端中编写此命令:

    >>> exit()
    

    【讨论】:

    • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写出好的答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    • 2019-09-18
    相关资源
    最近更新 更多