Skip to content

Instantly share code, notes, and snippets.

@minikomi
Forked from j2labs/gist:2502467
Created April 27, 2012 04:21
Show Gist options
  • Save minikomi/2505719 to your computer and use it in GitHub Desktop.
Save minikomi/2505719 to your computer and use it in GitHub Desktop.
abusing python functions
>>> def foo():
... foo.x = 0
... foo.total = lambda: foo.x
... def add(x):
... foo.x = foo.x + x
... return foo
... foo.add = add
...
>>> foo()
>>> foo.total()
0
>>> foo.add(3).add(5).total()
8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment