python - 为什么 Twilio Rest API 中的 "from"后面有一个下划线?

标签 python twilio twilio-api

twilio python library ,我们有这个功能来创建消息:

从 twilio.rest 导入 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.

关于python - 为什么 Twilio Rest API 中的 "from"后面有一个下划线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38708834/

相关文章:

python-无法使用 Homebrew 安装的模块?

python - Websocket 握手状态 426

python - 我们可以下载 python 的 urllib2 库吗?

python - 调用元类基函数()时出错参数 1 必须是 code 而不是 str

javascript - 如何从 API 的重复 promise 中获取值?

Python Tornado 使用协程并行请求并处理异常

javascript - 使用 Twilio 对浏览器电话进行物理电话调用无法正常工作

twilio - Twilio 出站用户创建

webrtc - 可编程 api twilio : Can browser client join multiple rooms at same time

java - Twilio - 未找到请求的资源 Messages.json