[Tutor] Question about python decorators

Cameron Simpson cs at cskk.id.au
Mon Jul 11 19:09:43 EDT 2022


On 11Jul2022 22:29, nathan tech <nathan-tech at hotmail.com> wrote:
>For some reason though I have a library that is not behaving this way, 
>to example:
>
>@object.attr.method
>def function():
> do stuff
>
>works, but
>
>object.attr.method=func
>
>does not

That should be:

    func = object.attr.method(func)

Remember, a decorator takes a function and returns a function (often a 
new function which calls the old function).

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list