Skip to content

Instantly share code, notes, and snippets.

Created August 22, 2013 04:07
Show Gist options
  • Save anonymous/6303131 to your computer and use it in GitHub Desktop.
Save anonymous/6303131 to your computer and use it in GitHub Desktop.
class A(object):
def hook(self, f):
atime = 0
def intime(*args):
print atime
atime += 1
return f(*args)
return intime
>>> f = A().hook(lambda b: b + 1)
>>> f(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in intime
UnboundLocalError: local variable 'atime' referenced before assignment
>>>
@jdunck
Copy link

jdunck commented Aug 22, 2013

Incidentally, when people complain about python not having proper closure support, this is (sometimes) what they mean.

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