[英]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.