Iterating over a function call

Gerald Britton gerald.britton at gmail.com
Tue Feb 2 09:47:30 EST 2010


[snip]
>> 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