recursive decorator

Michele Simionato michele.simionato at gmail.com
Thu Sep 3 08:50:07 EDT 2009


On Sep 3, 12:19 am, Ethan Furman <et... at stoneleaf.us> wrote:
> Greetings, List!
>
> The recent thread about a recursive function in a class definition led
> me back to a post about bindfunc from Arnaud, and from there I found
> Michele Simionato's decorator module (many thanks! :-), and from there I
> began to wonder...
>
> from decorator import decorator
>
> @decorator
> def recursive1(func, *args, **kwargs):
>      return func(func, *args, **kwargs)
>
> @recursive1
> def factorial1(recurse, n):
>      if n < 2:
>          return 1
>      return n * recurse(n-1)
>
> factorial(4)
> TypeError: factorial1() takes exactly 2 arguments (1 given)

What are you trying to do here? I miss why you don't use the usual
definition of factorial.
If you have a real life use case which is giving you trouble please
share. I do not see
why you want to pass a function to itself (?)

                            M. Simionato



More information about the Python-list mailing list