Getting method from within method?

David M. Cooke cookedm at physics.mcmaster.ca
Tue Jul 18 20:47:05 EDT 2000


I want to do recursion, like this:

def factorial(n):
    if n <= 1: return 1
    else return n * factorial(n-1)

However, this depends on the name of the method staying the same. For
instance, if I did this:

fact = factorial
factorial = None

fact(5) would give me an error since factorial isn't a method anymore.
It would be nice if there was some way of referring to the method
inside of the method.

Is there any way of doing this easily?

-- 
|>|\/|<
----------------------------------------------------------------------------
David M. Cooke
cookedm at mcmaster.ca



More information about the Python-list mailing list