Skip to content

Instantly share code, notes, and snippets.

@theharveyz
Last active December 22, 2016 19:17
Show Gist options
  • Save theharveyz/34d95261a38678ddb4846505da2f04b6 to your computer and use it in GitHub Desktop.
Save theharveyz/34d95261a38678ddb4846505da2f04b6 to your computer and use it in GitHub Desktop.
python decorator装饰器测试: 装饰器在代码加载时就会执行! 最简单的装饰器就是将函数直接返回(dummyDecorator)
# -*- 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