Skip to content

Instantly share code, notes, and snippets.

@ryanmark
Created July 10, 2015 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmark/d6055dd1601817ca42f2 to your computer and use it in GitHub Desktop.
Save ryanmark/d6055dd1601817ca42f2 to your computer and use it in GitHub Desktop.
Why does this script throw an UnboundLocalError?
#!/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