Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created January 13, 2016 20:08
Show Gist options
  • Select an option

  • Save jeffbrl/82cb1b0496d09d1739f7 to your computer and use it in GitHub Desktop.

Select an option

Save jeffbrl/82cb1b0496d09d1739f7 to your computer and use it in GitHub Desktop.
Simple decorator example with functools.wraps
#!/usr/bin/env python3
from functools import wraps
def add_sandwich(wrapped):
''' add_sandwich doc_string '''
# try commenting out the next line to see what happens
@wraps(wrapped)
def wrapper(*args, **kwargs):
''' wrapper doc_string'''
return wrapped(*args, **kwargs) + ' sandwich'
return wrapper
@add_sandwich
def ham():
''' Returns the string ham '''
return 'ham'
retval = ham()
print(retval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment