for loop without variable

Hrvoje Niksic hniksic at xemacs.org
Thu Jan 10 02:42:16 EST 2008


Mike Meyer <mwm-keyword-python.b4bdba at mired.org> writes:

> It sounds to me like your counter variable actually has meaning,

It depends how the code is written.  In the example such as:

for meaningless_variable in xrange(number_of_attempts):
    ...

the loop variable really has no meaning.  Rewriting this code only to
appease pylint is exactly that, it has nothing with making the code
more readable.

> you've hidden that meaning by giving it the meaningless name "i". If
> you give it a meaningful name, then there's an obvious way to do it
> (which you listed yourself):
>
>     while retries_left:
[...]

This loop contains more code and hence more opportunities for
introducing bugs.  For example, if you use "continue" anywhere in the
loop, you will do one retry too much.



More information about the Python-list mailing list