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

MRAB google at mrabarnett.plus.com
Wed Jan 9 20:34:09 EST 2008


On Jan 9, 11:17 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> "Diez B. Roggisch" <de... at nospam.web.de> 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.
>
Perhaps a "discarded" identifier should be any which is an underscore
followed by digits.

A single leading underscore is already used for "private" identifiers,
but they are usually an underscore followed by what would be a valid
identifier by itself, eg. "_exit".

The convention would then be:

2 underscores + valid_by_self + 2 underscores => special

underscore + valid_by_self => private

underscore + invalid_by_self => dummy



More information about the Python-list mailing list