在twilio python library,我们有这个功能来创建消息:为什么在Twilio Rest API中的“from”后面有下划线?
from twilio.rest import TwilioRestClient
,我们可以这样写:
msg = TwilioRestClient.messages.create(body=myMsgString, from_=myNumber, to=yourNumber)
我的问题很简单:为什么下划线遵循from
参数?或者为什么是参数名称?是否因为from
是Python中的其他关键字,我们用带下划线后缀的关键字区分变量?这在这种情况下实际上是必要的吗?
你已经回答了你自己。你不能使用'from',因为它是一个关键字。 [PEP8](https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles)建议这样做并给出'class_'的例子。 – Holloway