Created
June 30, 2010 15:39
-
-
Save lvidarte/458811 to your computer and use it in GitHub Desktop.
decorator with functools.wraps
This file contains hidden or 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
from functools import wraps | |
def binary(func): | |
@wraps(func) | |
def to_bin(*args, **kwargs): | |
'''convert result to binary''' | |
return bin(func(*args, **kwargs)) | |
return to_bin | |
@binary | |
def foo(x): | |
'''does some math''' | |
return x * x | |
print foo.__name__ | |
print foo.__doc__ | |
print foo(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output:
foo
does some math
0b11001