Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Simon Forman <[EMAIL PROTECTED]> wrote:
> >David Bear wrote:
> >> Is there an easy way to get the current level of recursion? I don't mean
>                       .
>                       .
>                       .
> >import sys
> >
> >def getStackDepth():
> >    '''Return the current call stack depth.'''
> >    n = 1
> >    while True:
> >        try:
> >            sys._getframe(n)
> >        except ValueError:
> >            return n - 1
> >        n += 1
>                       .
>                       .
>                       .
> >This is an evil hack. Never use it.
>                       .
>                       .
>                       .
> *This* is evil?  I regularly see worse things here in clp.
>
> I'll elaborate slightly:  even though I'm among those who regularly
> emphasize that certain constructs have nearly no place in applica-
> tion, as opposed to "system", programming, counting stack frames to
> reach their end seems to me like a minor violation of coding hygiene.
> Am I missing something in your suggestion?

No, not really.  My "evil hack" comment was meant to point out that
even though the function would work, it wasn't great to use in
"production" code, and further, that although python easily permits
things like counting call stack depth, the better way to count the
level of recursion in a recursive function call was to, well, count it.
:-)

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to