Is using range() in for loops really Pythonic?

George Sakkis george.sakkis at gmail.com
Mon May 12 21:52:49 EDT 2008


On May 12, 7:03 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:

> Carl Banks <pavlovevide... 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.

If you push this logic too far, you should del every name immediately
after the last statement it is used in the scope. I would generally
find less readable some code spread with del every few lines, micro-
managing the effective scope of each name. YMMV.

George



More information about the Python-list mailing list