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 anyone know for what this underscore stands for?
Thanks in advance.
-
2underscore is a valid variable name in python. in this case it's most likely some i18n functionSilentGhost– SilentGhost2010年07月09日 13:07:21 +00:00Commented Jul 9, 2010 at 13:07
-
1I'm going to guess it's for i18n/localization.Garrett– Garrett2010年07月09日 13:09:03 +00:00Commented Jul 9, 2010 at 13:09
-
1Most likely the same as these underscores: stackoverflow.com/questions/3077227/…Justin Ardini– Justin Ardini2010年07月09日 13:10:05 +00:00Commented Jul 9, 2010 at 13:10
-
Ironically enough, it is actual code from the mercurial.utilSilentGhost– SilentGhost2010年07月09日 13:14:33 +00:00Commented Jul 9, 2010 at 13:14
5 Answers 5
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.
2 Comments
from wx import GetTranslation as _.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.
Comments
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.
Comments
As others have mentioned, the _ is a function. The usual convention is that it used for localisation and internationalisation
Comments
The _ function is usually aliased to the GetText get function: http://docs.python.org/library/gettext.html