syntax questions
Philippe Gendreau
philippe.gendreau at savoirfairelinux.com
Wed Jul 24 13:56:16 EDT 2002
* Fredrik Lundh <fredrik at pythonware.com> [2002-07-24 16:56]:
> 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.
lol, it is indeed a translation function.
>
> > 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...)
I agree, I didn't write this code, but it just felt wrong.
I'll have a look at the styleguide, thanks for the help.
--
Philippe Gendreau
More information about the Python-list
mailing list