what does 'for _ in range()' mean?

Skip Montanaro skip at pobox.com
Fri Jul 30 13:26:17 EDT 2004


    Dave> Speaking of which, am I the only one here that sees this _()
    Dave> function as a total hack?

It's a convention adopted by the i18n folks which got imported to Python.
Preexisting tools that wander through the source and build dictionaries of
string literals will work with C, Python or Perl (or whatever).  The string

    "My dog has fleas"

becomes

    _("My dog has fleas")

That construct is a valid function call in many popular languages.

There's an extra side benefit as well.  To internationalize code that
contains string literals you want to disturb code readability as little as
possible.  _(...) seems to be the least visually obtrusive function call
available.

So, yes it's a hack, maybe even a total hack, but it's a hack with
history. <wink>

Skip



More information about the Python-list mailing list