Getting method from within method?
Aahz Maruch
aahz at netcom.com
Tue Jul 18 22:48:28 EDT 2000
In article <qnkitu3gd4m.fsf at arbutus.physics.mcmaster.ca>,
David M. Cooke <cookedm at physics.mcmaster.ca> wrote:
>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.
While there are ways of getting to what you claim you want, IMO the most
appropriate answer is to remind you of the old joke:
"Doctor, it hurts when I whack my knee with a hammer."
"Well, don't do that!"
--
--- Aahz (Copyright 2000 by aahz at netcom.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
Q: In a lesbian relationship, who decides who gets to be the man?
A: It's two women. There is no man. That's the point.
More information about the Python-list
mailing list