Iterating over a function call

Gerald Britton gerald.britton at
Tue Feb 2 15:47:30 CET 2010

>> 2. side effect of (maybe) leaking the iterator variable "value" into
>> the code following the loop (if the iterator is not empty).
> So? it is sometime useful.

Except that you can't guarantee that it will be set since the for loop
will not execute if the iterable is empty.

>> I can take care of 2 by explicitly deleting the variable at the end:
>>    del value
>> but I'd probably forget to do that sometimes.
> So? If having 'value' bound breaks your subsequent code, I consider it
> buggy.

Quite so.  I just like to eliminate the possibility up front.  If
'value' is never bound, the the bug will show up sooner.

Gerald Britton

More information about the Python-list mailing list