I've found the following syntax in a python file:
units = (
(100, 1 << 30, _('%.0f GB')),
(10, 1 << 30, _('%.1f GB')),
(1, 1 << 30, _('%.2f GB')),
(100, 1 << 20, _('%.0f MB')),
(10, 1 << 20, _('%.1f MB')),
(1, 1 << 20, _('%.2f MB')),
(100, 1 << 10, _('%.0f KB')),
(10, 1 << 10, _('%.1f KB')),
(1, 1 << 10, _('%.2f KB')),
(1, 1, _('%.0f bytes')),
)
Does a开发者_如何学Gonyone know for what this underscore stands for?
Thanks in advance.
Underscore is a valid variable name, so you have to look at the context of your example code. Obviously the underscore is a method which has been defined somewhere else. Usually it's used for translation stuff or similar things.
Look further up in the file. With some luck you'll find a statement like this:
from Language import _
Underscore is often used for i18n.
As said in other answers, _
is a valid name for a Python function. It's probable you will find _()
used as translation function in some I18N packages.
As others have mentioned, the _
is a function. The usual convention is that it used for localisation and internationalisation
The _ function is usually aliased to the GetText get function: http://docs.python.org/library/gettext.html
精彩评论