2

I see _ in some code before strings, e.g.

lable = _("Password")

What does it mean? One told me it is for multilanguage support. I have not found anything on the internet to confirm this...

Many thanks for your help.

. --update-- Thanks, @thg435 , after seeing your text, I've found exactly what is:

from django.utils.translation import ugettext, ugettext_lazy as _

'-' is a shorthand...

user3108063
  • 85
  • 1
  • 5

2 Answers2

6

The name _ is often defined as an alias to gettext.gettext, see http://docs.python.org/2/library/gettext.html for details. Yes, it's for internationalization.

However, since _ is a valid identifier (and hence a function name), it can be used for other purposes. It's completely up to the programmer.

georg
  • 211,518
  • 52
  • 313
  • 390
1

As per the docs, a valid Python identifier can be like this

identifier ::=  (letter|"_") (letter | digit | "_")*

It can be any valid expression, starting with a letter or _ and then it can have letters, digits or _. So, _ is a valid variable name in Python. Your code looks like a function call, where the name of the function is _. For example,

def _(arg):
    print arg

_("Password")

would print

Password
thefourtheye
  • 233,700
  • 52
  • 457
  • 497