-
-
Save minikomi/2505719 to your computer and use it in GitHub Desktop.
abusing python functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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