Nested loop limit?

Nelson Minar nelson at monkey.org
Wed Jul 7 18:56:14 EDT 2004


Why does CPython have a limit of 21 nested blocks?

I'm never going to write code this deeply nested by hand, but I could
imagine writing a program that does. It's also sort of a weird limit.

Peter Hansen <peter at engcorp.com> writes:
>  >>> for n in range(100):
> ...   exec '\n'.join([(' ' * i) + 'for i%s in range(2):' % i for i in
> range(n)])
>   + '\n' + ' ' * n + 'pass\n'
> ...
> Traceback (most recent call last):
>    File "<stdin>", line 2, in ?
> SystemError: too many statically nested blocks
>  >>> print n
> 21
> 
> Yes. :-)
> 
> -Peter

-- 



More information about the Python-list mailing list