2

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

max
  • 3,614
  • 9
  • 59
  • 107
  • Maybe the argument should be a dictionary, not separate parameters? – Barmar Sep 07 '16 at 16:26
  • 1
    They have a Python API, but no detailed documentation for how to use it? – Barmar Sep 07 '16 at 16:27
  • From the docs https://docs.python.org/3/reference/lexical_analysis.html#keywords. Reserved words **cannot** be used as ordinary identifiers – cjds Sep 07 '16 at 16:27
  • @Barmar no python is not very popular where i am , so they dont have doc at all ! – max Sep 07 '16 at 16:28

2 Answers2

9

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
5

Maybe try it like this:

sms_kwargs = {
    'toNum': '0666666666666',
    'messageContent': 'test',
    'messageType': 'normal',
    'user': 'myusername',
    'pass': '123456'
}
response = client.service.SendSMS(**sms_kwargs)
denvaar
  • 2,174
  • 2
  • 22
  • 26