为什么“def InvalidArgsSpecified:”是这样的?语法错误?

发布于 2024-08-16 07:57:12 字数 747 浏览 2 评论 0原文

我刚刚开始学习 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕梦 2024-08-23 07:57:12

语法错误位于第一行,您可以

def InvalidArgsSpecified:

将其更改为:

def InvalidArgsSpecified():

这些括号在 def 中是强制性的,即使它们之间没有任何内容(就像括号始终用于 调用一个函数——空括号,在这种情况下,如果您不带参数调用)。

编辑:现在OP在尝试在第9行调用此函数时遇到错误:由于此函数定义超过9行,因此可能会被调用(从模块顶层,而不是从内部)另一个函数)在定义之前,在这种情况下,简单的解决方法是仅在定义之后调用它。如果有比这更微妙的事情,我们需要查看代码来为您调试它!-)

The syntax error is in the very first line, where you have:

def InvalidArgsSpecified:

change it to:

def InvalidArgsSpecified():

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!-)

请叫√我孤独 2024-08-23 07:57:12

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

def InvalidArgsSpecified():

A function without arguments must still include brackets, e.g.:

def InvalidArgsSpecified():
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文