Skip to content

Instantly share code, notes, and snippets.

@includeamin
Last active June 12, 2019 11:39
Show Gist options
  • Save includeamin/0204ccf3035602267fbe28d37499f495 to your computer and use it in GitHub Desktop.
Save includeamin/0204ccf3035602267fbe28d37499f495 to your computer and use it in GitHub Desktop.
python Decorator with arguments
#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