Is using range() in for loops really Pythonic?

Carl Banks pavlovevidence at gmail.com
Sun May 11 21:52:48 EDT 2008


On May 11, 6:44 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> In such cases, the name 'dummy' is conventionally bound to the items
> from the iterator, for clarity of purpose::
>
>     for dummy in range(10):
>         # do stuff that makes no reference to 'dummy'

Is this documented?  I've never heard of this convention.  It's not
PEP 8, and I've never seen consistent usage of any name.  I'd be
interested in knowing where you read that this was a convention, or in
what subcommunities it's a convention in.

I think dummy is a terrible name to use for this, since in no other
usage I can think of does the word "dummy" suggest something isn't
used.  In fact, quite the opposite.  For example, the dummy_threads
module is most definitely used; the word dummy means that it's
stripped down.  Based on that, your usage of the symbol dummy above
would suggest to me that it's a value used in lieu of something else
(such as a calculated value).

In mathematics, a dummy argument another name for the independent
variable of a function (or more accurately, the symbol used to
represent it), which also doesn't match your usage.

If a value isn't used, then I think the most clear name for it is
"unused".


Carl Banks



More information about the Python-list mailing list