When reading source code of Django, I find some statements:
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")
I know it set description as 'Integer', but don't understand the syntax: description = _("Integer")
.
Can some one help on it?
Please read up on Internationalization (i18n)
http://docs.djangoproject.com/en/dev/topics/i18n/
The _
is a commonly-used name for the function that translates strings to another language.
http://docs.djangoproject.com/en/dev/topics/i18n/translation/#standard-translation
Also, read all of these related questions on SO:
https://stackoverflow.com/search?q=%5Bdjango%5D+i18n
Not an answer to your case but the more general "What's the meaning of '_' in python?":
In interactive mode, a _
will return the last result that wasn't assigned to a variable
>>> 1 # _ = 1 1 >>> _ # _ = _ 1 >>> a = 2 >>> _ 1 >>> a # _ = a 2 >>> _ # _ = _ 2 >>> list((3,)) # _ = list((3,)) [3] >>> _ # _ = _ [3]
Not sure, but it seems like every expression that's not assigned to a variable is actually assigned to _
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With