Last active
June 22, 2017 18:40
-
-
Save xevix/d3082a0372174f8e624415f7fb395f9d to your computer and use it in GitHub Desktop.
Iterator accessible after its scope ends
This file contains 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
def main(): | |
ary = ['I should never print'] | |
for elem in ary: | |
pass | |
other_ary = ['other'] | |
for other_elem in other_ary: | |
# "elem" hould not be defined here, but this works, because of Python's awful scoping rules | |
# which scope all variable declarations to the function scope | |
# See: http://eli.thegreenplace.net/2015/the-scope-of-index-variables-in-pythons-for-loops/ | |
print elem | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment