tags:

views:

117

answers:

5

Hi

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.

+3  A: 

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.

Achim
rudimenter
It may get overused, but it's certainly convenient at times. In a User Interface I'm designing we do something like this to simplify translations: `from wx import GetTranslation as _`.
g.d.d.c
+3  A: 

As reported from SilentGhost, _ is a valid name for a Python function. I agree with him that it's probably the name used by some i18n packages to translate the string passed as argument.

kiamlaluno
+2  A: 

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.

Ralph
+1  A: 

As others have mentioned, the _ is a function. The usual convention is that it used for localisation and internationalisation

Rory
A: 

The _ function is usually aliased to the GetText get function: http://docs.python.org/library/gettext.html

mkotechno