Last active
August 29, 2015 14:24
-
-
Save kevinschaul/616ac644941a84048021 to your computer and use it in GitHub Desktop.
Python scope probs
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
my_map = {} | |
crazier_tho = {} | |
def main(): | |
my_map = { | |
'hello': 'hi' | |
} | |
print my_map | |
printMyMap() | |
crazier_tho['hello'] = 'hi' | |
print crazier_tho | |
printCrazierTho() | |
def printMyMap(): | |
print my_map | |
def printCrazierTho(): | |
print crazier_tho | |
if __name__ == '__main__': | |
main() | |
# Prints: | |
# {'hello': 'hi'} | |
# {} | |
# {'hello': 'hi'} | |
# {'hello': 'hi'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe this: http://stackoverflow.com/a/292502
Look at the comment a bit down:
"As a caveat to Global access - reading a global variable can happen without explicit declaration, but writing to it without declaring global(var_name) will instead create a new local instance."
It seems like you are creating a local variable that hides the global