Last active
June 12, 2019 11:39
-
-
Save includeamin/0204ccf3035602267fbe28d37499f495 to your computer and use it in GitHub Desktop.
python Decorator with arguments
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
#https://pybit.es/decorator-optional-argument.html | |
from functools import wraps | |
import time | |
def sleep(seconds=None): | |
def real_decorator(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
print('Sleeping for {} seconds'.format(seconds)) | |
time.sleep(seconds if seconds else 1) | |
return func(*args, **kwargs) | |
return wrapper | |
return real_decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment