Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there an underscore following the "from" in the Twilio Rest API?

In the twilio python library, we have this feature to create messages:

from twilio.rest import TwilioRestClient

and we can write:

msg = TwilioRestClient.messages.create(body=myMsgString, from_=myNumber, to=yourNumber)

My question is simple: why does an underscore follow the from parameter? Or why is that the parameter name? Is it because from is otherwise a keyword in Python and we differentiate variables from keywords with an underscore suffix? Is that actually necessary in this case?

like image 385
Newb Avatar asked Aug 01 '16 22:08

Newb


1 Answers

This is because from would be an invalid argument name, resulting in a SyntaxError - it's a python keyword.

Appending a trailing underscore is the recommended way to avoid such conflicts mentioned in the PEP8 style guide:

If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption.

like image 84
wim Avatar answered Sep 29 '22 13:09

wim