我正在测试一些带有*args
和**kwargs
的代码,并为**kwargs
编写了一个字典。由于某种原因,我得到了:
def func(*args, **kwargs):
if args:
second_test(*args)
elif kwargs:
second_test(**kwargs)
def second_test(stringa, integera, floata):
print("Name: %s, Problems Correct: %d, Points: %f" % (stringa, integera, floata))
profile_1 = ["David", 21, 132.00]
func(*profile_1)
profile_1a = {'Name': 'David', 'Problems Correct': 21, 'Points': 132.00}
func(**profile_1a)
代码从第44行
开始,到第57行
结束。这是我遇到的错误:
TypeError: second_test() got an unexpected keyword argument 'Name'
我在谷歌上搜索了“unexpected keyword argument”,但我找不到定义,只有其他的stackoverflow文章。我的代码有什么问题?
second_test
不接受名为Name
的关键字参数。从第二次调用func(**profile_1a)
开始,按照代码的流程即可。 - 9769953**profile_1a
是什么?意思是,当您使用**
作为字典的前缀时,您认为发生了什么? - ChatterOne