syntax questions

Fredrik Lundh fredrik at pythonware.com
Wed Jul 24 12:56:07 EDT 2002


Philippe Gendreau wrote:
> I'm fairly new to python and there a thing I don't understand in the
> syntax. What is it with the "_". I have seen it used in many places for
> what seems to be different puposes like:
>
> from x import _

here, you're importing something named "_" (most likely
a function) from the x module.

judging from your example, the "_" function is probably
used to translate strings from english to the local language.

for some reason, people doing internationalization (i18n) and
localization (l10n) stuff seem to prefer to use functions called
"_", probably only to confuse people like you and me.

> Also, I'd like to understand this syntax: "((_(name),))"

the _(name) part is simply a call to the translation function.
it could have been written like, say

    local_name = _(name)

or even

    local_name = translate(name)

the (x,) part creates a tuple containing a single item (see the
tutorial and the language reference for more info on tuples).

    a_tuple = (local_name,)

the outermost () belongs to the append method call:

    theme.append(a_tuple)

(according to the python style guide, and common sense, it's
bad style to put a space between the function/method name
and the parentheses...)

</F>





More information about the Python-list mailing list