Created
January 13, 2016 20:08
-
-
Save jeffbrl/82cb1b0496d09d1739f7 to your computer and use it in GitHub Desktop.
Simple decorator example with functools.wraps
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
| #!/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