在python中处理GAE项目时,我注意到我的IDE(eclipse)提出了几种看似相同的方法:
我将使用此API发送电子邮件,according to the docs应使用send_mail
。然而,当我在日食中看到SendMail
时,我开始怀疑其中是否有一个被弃用了,所以我去寻找有关它的信息。
我遇到了the page that documents the functions that the mail api offers并注意到SendMail
没有包含在那里,我觉得很奇怪。
我做的下一件事是检查source code for the mail api是否有任何可以告诉我更多相关信息的内容,并且(第376行)我找到了:
def send_mail(sender,
to,
subject,
body,
make_sync_call=apiproxy_stub_map.MakeSyncCall,
**kw):
"""Sends mail on behalf of application.
Args:
sender: Sender email address as appears in the 'from' email line.
to: List of 'to' addresses or a single address.
subject: Message subject string.
body: Body of type text/plain.
make_sync_call: Function used to make sync call to API proxy.
kw: Keyword arguments compatible with EmailMessage keyword based
constructor.
Raises:
InvalidEmailError when invalid email address provided.
"""
kw['sender'] = sender
kw['to'] = to
kw['subject'] = subject
kw['body'] = body
message = EmailMessage(**kw)
message.send(make_sync_call)
SendMail = send_mail
引起我注意的是底线
SendMail = send_mail
结论:它们是一样的。通过不同的名称两次提供相同功能的原因是什么?
我搜索了一下,试图找到你想要这样做的原因,但我找不到任何东西。虽然我显然不是专家,但它似乎没有增加任何价值。
答案 0 :(得分:2)
我怀疑这只是谷歌内部风格与公众风格不同的一个例子。在内部,Python样式指南为所有函数和方法以及类强制执行CamelCase(不知道为什么)。在外部,他们遵循PEP8建议的功能是lower_case_with_underscore。这种别名只是从一种风格转换为另一种风格。