for loop without variable

Dan Sommers me at privacy.net
Wed Jan 9 20:35:45 EST 2008


On Wed, 09 Jan 2008 14:25:36 -0800, erik gartz 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 ...

What does that loop do?  (Not the loop you posted, but the "real" loop
in your application.)  Perhaps python has another way to express what
you're doing.

For example, if you're iterating over the elements of an array, or
through the lines of a file, or the keys of a dictionary, the "in"
operator may work better:

    for thing in array_or_file_or_dictionary:
        do_something_with(thing)

HTH,
Dan

-- 
Dan Sommers                                   A death spiral goes clock-
<http://www.tombstonezero.net/dan/>           wise north of the equator.
Atoms are not things. -- Werner Heisenberg              -- Dilbert's PHB



More information about the Python-list mailing list