Skip to content

Instantly share code, notes, and snippets.

@kuozo
Created Jul 31, 2011
Embed
What would you like to do?
Decorator
#一个简单的装饰器
def require_int(foo):
def re(arg):
if type(arg)==int:
return foo(arg)
else :
raise 'The arg must int'
return re
@require_int
def get_int(arg):
return 'the arg is {0}'.format(arg)
get_int(1)
#ok
get_int(20)
#ok
get_int('test')
#error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment