为什么`def InvalidArgsSpecified:`是语法错误?

2024-10-03 17:21:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚开始学python。。。所以请忍受我吧

为什么这段代码会给我一个无效的语法错误

def InvalidArgsSpecified:
    print ("*** Simtho Usage ***\n")
    print ("-i Installs Local App,, include full path")
    print ("-u Uninstalls Installed App,include ID or Name")
    print ("-li Lists all installed Apps and their ID")
    print ("-all Lists All Apps in Repository")
    print ("-di Downloads and Installs App from repository, enter the title or id number")
    print ("-dw Downloads and Installs Single App from a full link")
    print ("-rmall Removes All Packages installed and removes Simtho itself\n")
    print ("*** End of Simtho Usage ***")
    sys.exit()

编辑:现在说它在第9行没有定义 9号线是

^{pr2}$

Tags: appsinstalledorandidappincludeusage
2条回答

语法错误位于第一行,其中包含:

def InvalidArgsSpecified:

将其更改为:

^{pr2}$

即使它们之间没有任何内容(就像括号总是用来调用函数空括号一样,如果您在没有参数的情况下调用),这些括号在^{cd1>}中是强制性的。

编辑:现在OP在第9行尝试调用此函数时出错:由于此函数定义超过9行,因此在定义之前,可能正在调用(从模块顶层,而不是从其他函数中调用),在这种情况下,简单的修复方法是只在定义之后调用它。如果它比这更微妙,我们需要看到代码来调试它!-)

没有参数的函数必须仍然包含方括号,例如:

def InvalidArgsSpecified():

相关问题 更多 >