为什么“def InvalidArgsSpecified:”是这样的?语法错误?
我刚刚开始学习 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号线是
InvalidArgsSpecified()
I'm just starting to learn python... so bear with me please
Why is it giving me a Invalid Syntax error with this block of code
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()
edit: Now its saying that it's undefined at line 9
Line 9 is
InvalidArgsSpecified()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
语法错误位于第一行,您可以
将其更改为:
这些括号在
def
中是强制性的,即使它们之间没有任何内容(就像括号始终用于 调用一个函数——空括号,在这种情况下,如果您不带参数调用)。编辑:现在OP在尝试在第9行调用此函数时遇到错误:由于此函数定义超过9行,因此可能会被调用(从模块顶层,而不是从内部)另一个函数)在定义之前,在这种情况下,简单的解决方法是仅在定义之后调用它。如果有比这更微妙的事情,我们需要查看代码来为您调试它!-)
The syntax error is in the very first line, where you have:
change it to:
Those parentheses are mandatory in a
def
, even when there's nothing between them (just as parentheses are always used to call a function -- empty parentheses, in that case, if you're calling without arguments).Edit: now the OP's getting an error for trying to call this function in line 9: since this function definition is more than 9 lines, it's probably getting called (from module top-level, rather than from within another function) before it's defined, in which case the simple fix is to call it only after it's defined. If it's anything subtler than that, we'll need to see the code to debug it for you!-)
没有参数的函数仍然必须包含括号,例如:
A function without arguments must still include brackets, e.g.: