for loop without variable

John Machin sjmachin at lexicon.net
Wed Jan 9 18:57:11 EST 2008


On Jan 10, 10:00 am, Tim Chase <python.l... at tim.thechases.com> wrote:
> >> Hi. I'd like to be able to write a loop such as:
> >> for i in range(10):
> >>     pass
> >> but without the i variable. The reason for this is I'm using pylint
> >> and it complains about the unused variable i.
>
> > if a computer tells you to do something stupid, it's often better to
> > find a way to tell the computer to shut up than to actually do some-
> > thing stupid.
>
> > (pylint's online documentation is remarkably unreadable, so I cannot
> > help you with the details, but surely there's a way to disable that
> > test, either globally, or for a specific region of code?).
>
> That documentation on PyLint[1] is atrocious!
>
>  From my reading of it, at the beginning of your file, you put a
> comment something like
>
>    # pylint: disable-msg=W0612
>
> which should disable that particular message.  Totally untested.
>
> I don't know if PyLint is smart enough, but if you don't use "i",
> you might use the common "throwaway" variable of "_":
>
>    for _ in xrange(10):
>      do_something()
>
> in which case it _might_ recognize that it's a throwaway variable
> and not warn you about it.  At least that would be nice of it.
> But given the abusive nature of the documenation, I'm not sure
> that's the case ;)
>
> -tkc
> [1]http://www.logilab.org/card/pylintfeatures

I didn't get as far as the allegedly "abusive" part. I followed the
link that you gave, but no matter what I clicked on, it would go
looking for an obviously incorrect URL like http://www.logilab.org/#messages-control-options
and just go (slowly!) to the home page ...



More information about the Python-list mailing list