为什么 Twilio Rest API 中的 "from" 后面有一个下划线?
Why is there an underscore following the "from" in the Twilio Rest API?
在twilio python library中,我们有这个功能来创建消息:
from twilio.rest import TwilioRestClient
我们可以这样写:
msg = TwilioRestClient.messages.create(body=myMsgString, from_=myNumber, to=yourNumber)
我的问题很简单:为什么下划线跟在 from
参数后面?或者为什么是参数名称?是否因为 from
是 Python 中的关键字,我们将变量与带有下划线后缀的关键字区分开来?在这种情况下真的有必要吗?
这是因为 from
将是一个无效的参数名称,导致 SyntaxError
- 这是一个 python 关键字。
为避免 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.
在twilio python library中,我们有这个功能来创建消息:
from twilio.rest import TwilioRestClient
我们可以这样写:
msg = TwilioRestClient.messages.create(body=myMsgString, from_=myNumber, to=yourNumber)
我的问题很简单:为什么下划线跟在 from
参数后面?或者为什么是参数名称?是否因为 from
是 Python 中的关键字,我们将变量与带有下划线后缀的关键字区分开来?在这种情况下真的有必要吗?
这是因为 from
将是一个无效的参数名称,导致 SyntaxError
- 这是一个 python 关键字。
为避免 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.