python类的⽅法中必须有⼀个什么参数_python–类⽅法需要1
个位置参数,但是给出了。。。
那是合乎逻辑的:**凭证意味着你将提供它的命名参数.但是你没有提供字典的名称.
这⾥有两种可能性:
>您使⽤凭证作为单个参数,并将其传递给字典,如:
def submit_new_account_form(self, credentials):
# ...
pass
loginpage.submit_new_account_form({'first_name': 'Test', 'last_name': 'Test', 'phone_or_email': temp_email, 'newpass':
'1q2w3e4r5t', 'sex': 'male'})
>通过在前⾯放两个星号,将字典作为命名参数传递:
但是你没有
def submit_new_account_form(self, **credentials):
# ...
pass
loginpage.submit_new_account_form(**{'first_name': 'Test', 'last_name': 'Test', 'phone_or_email': temp_email, 'newpass':
'1q2w3e4r5t', 'sex': 'male'})
第⼆种⽅法等于传递命名参数,如:
loginpage.submit_new_account_form(first_name='Test', last_name='Test', phone_or_email=temp_email,
newpass='1q2w3e4r5t', sex='male')
我认为最后⼀种⽅法是更清晰的语法.此外,它允许您轻松修改submit_new_account_form函数签名的签名以⽴即捕获某些参数,⽽不是将它们包装到字典中.