Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Created June 30, 2010 15:39
Show Gist options
  • Save lvidarte/458811 to your computer and use it in GitHub Desktop.
Save lvidarte/458811 to your computer and use it in GitHub Desktop.
decorator with functools.wraps
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)
@lvidarte
Copy link
Author

output:
foo
does some math
0b11001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment