【问题标题】:Python is detecting syntax error that's rightPython 正在检测正确的语法错误
【发布时间】:2020-01-12 01:54:42
【问题描述】:

我正在观看有关如何制作视频游戏的 YouTube 教程,现在我们将其转换为 exe,这是我将游戏转换为 exe 的设置代码(不是游戏代码本身):

import cx_Freeze

executables = [cx_Freeze.Executable("pygame sentdex.py")]

cx_Freeze.setup(
    name="A bit racey",
    options={"build_exe": {"packages":["pygame"],
                           "include_files":["car.png"]}} #if you have other included files put them here. like fonts.
    executables = executables)

当我尝试转换时,会发生这种情况:

    PS C:\Users\Damon Tattersfield\Desktop\video game\code\python codes> python setup.py build
  File "setup.py", line 9
    executables = executables)
    ^
SyntaxError: invalid syntax
PS C:\Users\Damon Tattersfield\Desktop\video game\code\python codes>

它一直说executables 中的 e 是错误的,即使它对 YouTuber 来说工作正常,我已将其更改为大写 e,删除,重新键入它,但它说这是一个语法错误,当我' m 99% 肯定不是。

这是YouTuber的链接:https://www.youtube.com/watch?list=PLQVvvaa0QuDdLkP8MrOXLe_rKuf6r80KO&v=EY6ZCPxqEtM

我该如何解决? 谢谢...

【问题讨论】:

  • 你可能遗漏了一个逗号,无论如何它可能与那个可怜的“e”无关。
  • options 后面好像少了一个逗号。即myfunc(a,b c),而不是myfunc(a,b,c)

标签: python pygame cx-freeze


【解决方案1】:

您需要在第二个关键字参数后添加一个逗号:

cx_Freeze.setup(
    name="A bit racey",
    options={"build_exe": {"packages":["pygame"],
                           "include_files":["car.png"]}}, # <-- HERE
    executables = executables)

通常当您收到SyntaxError 并且解释器告诉错误出现在例如第 9 行时,错误实际上是缺少逗号、括号或第 8 行的引号。

此外,每当您遇到异常/错误时,您永远不会“正确”。我可以向你保证,口译员不会误会这些。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    • 2011-07-19
    • 2012-06-18
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    相关资源
    最近更新 更多