Conventions for dummy name (was: for loop without variable)

Ben Finney bignose+hates-spam at
Thu Jan 10 00:17:46 CET 2008

"Diez B. Roggisch" <deets at> writes:

> The underscore is used as "discarded" identifier. So maybe
> for _ in xrange(10):
>     ...

The problem with the '_' name is that it is already well-known and
long-used existing convention for an entirely unrelated purpose: in
the 'gettext' i18n library, the '_' function to get the
locally-translated version of a text string.

Since the number of programs that need to use something like 'gettext'
(and therefore use the '_' function) is likely only to increase, it
seems foolish to set one's program up for a conflict with that
established usage.

I've seen 'dummy' used as a "don't care about this value" name in
other Python code. That seems more readable, more explicit, and less
likely to conflict with existing conventions.

 \       "It is forbidden to steal hotel towels. Please if you are not |
  `\        person to do such is please not to read notice."  -- Hotel |
_o__)                                         sign, Kowloon, Hong Kong |
Ben Finney

More information about the Python-list mailing list