Is using range() in for loops really Pythonic?

Ben Finney bignose+hates-spam at benfinney.id.au
Mon May 12 19:03:53 EDT 2008


Carl Banks <pavlovevidence at gmail.com> writes:

> IMHO, whether a varibale is used or not has got to be one of the least
> important things of all (in no small part because it's easily
> discernable from nearby code).

I couldn't disagree more.

If you're binding a name to a value that will never be used, you're
doing me (the reader of the code) a great favour if you indicate
clearly and concisely that this value is not intended to be referenced
anywhere else. Saving time for the reader is a very important job of
the writer of code.

> Having said that, if you do think it's most important to document
> whether something is used, I would suggest not using "_" (because
> it's conflicts with gettext conventions) or "dummy" (because it's
> misleading) for it.

Agreed.

Note, too, that the ideal answer to this is "don't bind names at all
to values that will never be used". It's only because the specifics of
Python's 'for' statement require us to do this that we are discussing
the ramifications of what to do when what Python requires of us is
actually unnecessary for our purposes.

-- 
 \          "Friendship is born at that moment when one person says to |
  `\      another, 'What! You too? I thought I was the only one!'"  -- |
_o__)                                                       C.S. Lewis |
Ben Finney



More information about the Python-list mailing list