变量名可以是python的关键字_使用python保留关键字作为变量名

1586010002-jmsa.png

im trying to send sms using a webservice , this is what webservice document suggest :

response = client.service.SendSMS( fromNum = '09999999' ,

toNum = '0666666666666',

messageContent = 'test',

messageType = 'normal',

user = 'myusername',

pass = '123456' ,

)

to be fair they dont have document for python only php/asp so i've converted this from their php sample but as unlike me some may know pass is a reserved keyword of python

so i cant have variable name pass becuz i get syntax error !

is there a way around trhis or i should switch to another webservice ? i wish we could put variable names in quotation mark or something

解决方案

You can pass in arbitrary strings as keyword arguments using the **dictionary call syntax:

response = client.service.SendSMS( fromNum = '09999999' ,

toNum = '0666666666666',

messageContent = 'test',

messageType = 'normal',

user = 'myusername',

**{'pass': '123456'}

)

You can move all the keyword arguments into a dictionary if you want to, and assign that dictionary to a variable before applying.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值