Skip to content

Instantly share code, notes, and snippets.

@kuozo
Created July 31, 2011 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuozo/1116755 to your computer and use it in GitHub Desktop.
Save kuozo/1116755 to your computer and use it in GitHub Desktop.
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