Last active
December 22, 2016 19:17
-
-
Save theharveyz/34d95261a38678ddb4846505da2f04b6 to your computer and use it in GitHub Desktop.
python decorator装饰器测试: 装饰器在代码加载时就会执行! 最简单的装饰器就是将函数直接返回(dummyDecorator)
This file contains 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
# -*- coding: utf-8 -*- | |
def dummy_decorator(injection): | |
print 'dummy' | |
return injection | |
def test_decorator(injection): | |
print 'foooo' | |
def wrapper(params): | |
print 'barrrr' | |
return injection(params) | |
return wrapper | |
@dummy_decorator | |
@test_decorator | |
def demo(params): | |
pass | |
if __name__ == '__main__': | |
pass | |
# output: | |
# foooo | |
# dummy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment