python类的方法中必须有一个什么参数_python – 类方法需要1个位置参数,但是给出了2个...

那是合乎逻辑的:**凭证意味着你将提供它的命名参数.但是你没有提供字典的名称.

这里有两种可能性:

>您使用凭证作为单个参数,并将其传递给字典,如:

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函数签名的签名以立即捕获某些参数,而不是将它们包装到字典中.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值