Bey*_*der 22 python django syntax
在阅读Django的源代码时,我发现了一些声明:
class Field(object):
"""Base class for all field types"""
__metaclass__ = LegacyConnection
# Generic field type description, usually overriden by subclasses
def _description(self):
return _(u'Field of type: %(field_type)s') % {
'field_type': self.__class__.__name__
}
description = property(_description)
class AutoField(Field):
description = _("Integer")
Run Code Online (Sandbox Code Playgroud)
我知道它将描述设置为'整数',但不理解语法:description = _("Integer").
有人可以帮忙吗?
S.L*_*ott 27
请阅读国际化(i18n)
http://docs.djangoproject.com/en/dev/topics/i18n/
这_是将字符串转换为另一种语言的函数的常用名称.
http://docs.djangoproject.com/en/dev/topics/i18n/translation/#standard-translation
另外,在SO上阅读所有这些相关问题:
https://stackoverflow.com/search?q=%5Bdjango%5D+i18n
Nic*_*k T 13
不是你的案例的答案,而是更一般的"python中'_'的含义是什么?":
在交互模式下,a _将返回未分配给变量的最后结果
>>> 1 # _ = 1
1
>>> _ # _ = _
1
>>> a = 2
>>> _
1
>>> a # _ = a
2
>>> _ # _ = _
2
>>> list((3,)) # _ = list((3,))
[3]
>>> _ # _ = _
[3]
Run Code Online (Sandbox Code Playgroud)
不确定,但似乎每个未分配给变量的表达式实际上都已分配给_.