Created
January 14, 2015 00:28
-
-
Save talwai/68bdceccdd97c4c4916f to your computer and use it in GitHub Desktop.
Python 2.7 Leaking scope in list comprehensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This leaks in Python 2.7 but does not in Python 3+ | |
def bad_scope_list(): | |
num = range(1,10) | |
i = 4 | |
print [i for i in num] | |
print i # Prints 9 instead of 4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment