简体   繁体   English

我该如何解决 SyntaxError:位置参数跟随关键字参数

[英]How can I slove SyntaxError: positional argument follows keyword argument

I am trying to run this code here:我正在尝试在这里运行此代码:

threads = [threading.Thread(name='ThreadNumber{}'.format(n),target=SB, args(shoe_type,model,variant)) for size in SizeList for n in range(ThreadCount)]

However this is what my terminal is returning:然而,这是我的终端返回的内容:

   threads = [threading.Thread(name='ThreadNumber{}'.format(n),target=SB, args(s
hoe_type,model,variant)) for size in SizeList for n in range(ThreadCount)]
                                                                           ^

SyntaxError: positional argument follows keyword argument

Is there anyway I can Fix this?无论如何我可以解决这个问题吗?

SB is referring a function that I am trying to run. SB 指的是我正在尝试运行的 function。

In Python, the order in which we pass (and receive) arguments to a function matters.在 Python 中,我们将 arguments 传递(和接收)到 function 的顺序很重要。

Positional arguments come first, variable-length arguments come next, vairable-length keyword arguments come last.位置arguments 首先出现,可变长度arguments 次之,可变长度关键字 arguments最后。

The expected syntax looks like this:预期的语法如下所示:

function(arg, *args, **kwargs)

The argument names above are only conventional examples, so a real-world function will look like:上面的参数名称只是常规示例,因此真实世界的 function 将如下所示:

about_user(name, *hobbies, **favorite_foods)

If we call (or receive) with the argument types out of order, we get errors similar to the one you encountered.如果我们使用无序的参数类型调用(或接收),我们会得到与您遇到的类似的错误。 In your specific case, your keyword arguments are first, when they should be last.在您的具体情况下,您的关键字 arguments 是第一个,而它们应该是最后一个。

I wrote asmall article about *args and **kwargs that has a few more related details and examples.我写了一篇关于*args**kwargs的小文章,其中包含更多相关的细节和示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SyntaxError:位置参数跟随关键字参数 - SyntaxError: positional argument follows keyword argument 语法错误:位置参数跟在关键字参数之后。 如何绕过它? - SyntaxError: positional argument follows keyword argument. How to bypass it? 未能更正:此错误 SyntaxError:位置参数跟随关键字参数 - failed to correct : this error SyntaxError: positional argument follows keyword argument SyntaxError:位置参数遵循 CNN model 中的关键字参数 - SyntaxError: positional argument follows keyword argument in CNN model Python celery任务画布:SyntaxError:位置参数紧跟关键字参数 - Python celery task canvas: SyntaxError: positional argument follows keyword argument Dash_table:SyntaxError:位置参数跟随关键字参数 - Dash_table: SyntaxError: positional argument follows keyword argument 语法错误:位置参数跟随关键字参数 [discord.py] - SyntaxError: positional argument follows keyword argument [discord.py] 对networkx失败:SyntaxError:关键字关键字后跟位置参数 - failed to networkx: SyntaxError: positional argument follows keyword argument 位置参数跟随关键字参数当我尝试分组时出错 - positional argument follows keyword argument Error when i try to group by 位置参数跟在关键字参数之后,不知道如何解决这个问题 - Positional argument follows keyword argument, not sure how to resolve this
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM