Skip to content

Instantly share code, notes, and snippets.

@tokibito
Created August 16, 2012 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokibito/3371676 to your computer and use it in GitHub Desktop.
Save tokibito/3371676 to your computer and use it in GitHub Desktop.
__call__ method
>>> class Counter:
... def __init__(self):
... self.value = 0
... def __call__(self):
... self.value += 1
... return self.value
...
>>> c = Counter()
>>> c()
1
>>> c()
2
>>> c()
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment