GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python-patterns/decorator.py at master · heyalexej/python-patterns Expand file tree/ Copy pathdecorator.pyMore file actions 31 lines (22 loc) · 748 Bytes / Copy pathdecorator.pyFile metadata and controls31 lines (22 loc) · 748 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 """https://docs.python.org/2/library/functools.html#functools.wraps""" """https://stackoverflow.com/questions/739654/how-can-i-make-a-chain-of-function-decorators-in-python/739665#739665""" from functools import wraps def makebold(fn): @wraps(fn) def wrapped(): return "<b>" + fn() + "</b>" return wrapped def makeitalic(fn): @wraps(fn) def wrapped(): return "<i>" + fn() + "</i>" return wrapped @makebold @makeitalic def hello(): """a decorated hello world""" return "hello world" if __name__ == '__main__': print('result:{} name:{} doc:{}'.format(hello(), hello.__name__, hello.__doc__)) ### OUTPUT ### # result:<b><i>hello world</i></b> name:hello doc:a decorated hello world |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |