Skip to content

Instantly share code, notes, and snippets.

@skimbrel
Created October 22, 2013 22:47
Show Gist options
  • Save skimbrel/7109522 to your computer and use it in GitHub Desktop.
Save skimbrel/7109522 to your computer and use it in GitHub Desktop.
In [13]: def counter_factory():
....: count = 0
....: def _counter():
....: count += 1
....: return _counter
....:
In [14]: f = counter_factory()
In [15]: f()
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-15-0ec059b9bfe1> in <module>()
----> 1 f()
<ipython-input-13-e9a70e60b268> in _counter()
2 count = 0
3 def _counter():
----> 4 count += 1
5 return _counter
UnboundLocalError: local variable 'count' referenced before assignment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment