Created
July 31, 2011 12:34
-
-
Save kuozo/1116755 to your computer and use it in GitHub Desktop.
Decorator
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
#一个简单的装饰器 | |
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