Skip to content

Instantly share code, notes, and snippets.

@dansondergaard
Created November 1, 2017 18:05
Show Gist options
  • Select an option

  • Save dansondergaard/69e9b5d579cd6c572e89b95cf9729647 to your computer and use it in GitHub Desktop.

Select an option

Save dansondergaard/69e9b5d579cd6c572e89b95cf9729647 to your computer and use it in GitHub Desktop.
"""Example of adding attributes to a function using a decorator."""
import time
def delayable(func):
def _delayer(delay, *args, **kwargs):
time.sleep(delay)
return func(*args, **kwargs)
setattr(func, 'delay', _delayer)
return func
@delayable
def say_hello(name):
print('Hello', name)
say_hello('Anne')
say_hello.delay(5, 'Dan')
say_hello.delay(10, 'Torben')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment