Can I undecorate a function?

Steve Holden steve at
Mon Jan 29 19:29:22 CET 2007

Matthew Wilson wrote:
> The decorator as_string returns the decorated function's value as
> string.  In some instances I want to access just the function f,
> though, and catch the values before they've been decorated.
> Is this possible?
> def as_string(f):
>     def anon(*args, **kwargs):
>         y = f(*args, **kwargs)
>         return str(y)
>     return anon
> @as_string
> def f(x):
>     return x * x
It's much simpler not to use the decorator syntax if you also want 
access to the original function.

Simply declare f as a function, then assign decorator(f) to some other name.

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Skype: holdenweb
Blog of Note:
See you at PyCon?

More information about the Python-list mailing list