[Tutor] inconsistent destruction
Japhy Bartlett
japhy at pearachute.com
Thu Aug 8 06:26:54 CEST 2013
you can either manually manage the memory with `del cnt` or let the built
in memory management .. manage the memory.
On Wed, Aug 7, 2013 at 10:54 PM, Jim Mooney <cybervigilante at gmail.com>wrote:
> This bugs me for some reason. The final variable is saved in a for
> loop but not in a list comprehension. It just seems to me they should
> both be destroyed to avoid confusion.
>
> lst = []
> for cnt in range(5):
> lst.append(cnt)
> cnt
> 4
>
> lst = [cnt2 for cnt2 in range(5)]
> cnt2
> builtins.NameError: name 'cnt2' is not defined
>
> Is there a form of for loop that would destroy the loop variable? I
> could always do del cnt right after the for, but that seems
> artificial.
>
> --
> Jim
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130807/f1c6b3bf/attachment.html>
More information about the Tutor
mailing list