Created
July 10, 2015 20:44
-
-
Save ryanmark/d6055dd1601817ca42f2 to your computer and use it in GitHub Desktop.
Why does this script throw an UnboundLocalError?
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
#!/usr/bin/env python | |
foo = 0 | |
bar = {'foo': 0} | |
def wtf(): | |
# Totally fine | |
bar['foo'] += 1 | |
# UnboundLocalError: local variable 'foo' referenced before assignment | |
foo += 1 | |
wtf() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment