Function attributes
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Wed Feb 10 14:04:58 EST 2010
On Wed, 10 Feb 2010 18:31:23 +0000, Arnaud Delobelle wrote:
> It's not ideal, but you can use a decorator like this to solve this
> problem:
>
> def bindfunction(f):
> def bound_f(*args, **kwargs):
> return f(bound_f, *args, **kwargs)
> bound_f.__name__ = f.__name__
> return bound_f
Ah, very nice. Perhaps it's better to use functools.wraps?
import functools
def bindfunction(f):
@functools.wraps(f)
def bound_f(*args, **kwargs):
return f(bound_f, *args, **kwargs)
return bound_f
--
Steven
More information about the Python-list
mailing list