Skip to content

Instantly share code, notes, and snippets.

@kevinclark
Created December 7, 2010 04:16
Show Gist options
  • Save kevinclark/731446 to your computer and use it in GitHub Desktop.
Save kevinclark/731446 to your computer and use it in GitHub Desktop.
>>> b = 0
>>> def incB():
... b += 1
...
>>> c = []
>>> def addC():
... c.append(1)
...
>>> b
0
>>> c
[]
>>> incB()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in incB
UnboundLocalError: local variable 'b' referenced before assignment
>>> addC()
>>> c
[1]
@gpshead
Copy link

gpshead commented Dec 7, 2010

Heh I wouldn't mind that either since I absolutely hate globals in code that are not constants declared in ALL_CAPS. I really doubt that'd fly if suggested on python-ideas@ though. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment