Created
April 14, 2017 07:53
-
-
Save pantuts/e737f94aa1cb8d0e08a91d17919220f4 to your computer and use it in GitHub Desktop.
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
import functools | |
def calltracker(func): | |
@functools.wraps(func) | |
def wrapper(*args): | |
wrapper.has_been_called = True | |
return func(*args) | |
wrapper.has_been_called = False | |
return wrapper | |
@calltracker | |
def doubler(number): | |
return number * 2 | |
if __name__ == '__main__': | |
if not doubler.has_been_called: | |
print("You haven't called this function yet") | |
doubler(2) | |
if doubler.has_been_called: | |
print('doubler has been called!') | |
# http://www.blog.pythonlibrary.org/2017/03/10/python-how-to-tell-if-a-function-has-been-called/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment