getrecursiondepth

Manlio Perillo NOmanlio_perilloSPAM at libero.it
Sat Sep 25 13:44:34 EDT 2004


On Sat, 25 Sep 2004 14:21:43 +0100, Michael Hoffman
<m.h.3.9.1.without.dots.at.cam.ac.uk at example.com> wrote:

>Manlio Perillo wrote:
>
>> Why the sys module does not have a function like getrecursiondepth?
>
>I might be ignorant, but how does this differ from sys.getrecursionlimit()?


>>> def foo(n = 0):
	print 'n = %d and recursion depth = %d' % (n,

getrecursiondepth())
	if n > 5: return
	foo(n + 1)


>>> foo()
n = 0 and recursion depth = 1
n = 1 and recursion depth = 2
n = 2 and recursion depth = 3
n = 3 and recursion depth = 4
n = 4 and recursion depth = 5
n = 5 and recursion depth = 6
n = 6 and recursion depth = 7



N.B.
The real recursion depth starts at 2 in foo, I have redefined the
origin.



Regards   Manlio Perillo



More information about the Python-list mailing list