Nested loop limit?
Michael Hudson
mwh at python.net
Fri Jul 9 09:49:17 EDT 2004
Peter Hansen <peter at engcorp.com> writes:
> Nelson Minar wrote:
>
> > 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.
>
> Is the fact that the limit is actually 20 less weird? (The 21 was
> where "n" was after it raised an exception, not the last legal
> amount of indentation.)
>
> And I think the answer is probably something like "CPython,
> being written in C, tends to have certain hard-coded limits
> much like C programs always do, rather than being nice and
> flexible like programs written with more sophisticated languages
> like, say, Python." :-)
Spot on. This has to do with the 'blockstack', very much an internal
detail to Python's implementation. We'd like to get rid of it (*not*
because we want to let people write code with more than 20 nested for
loops :-) but it's not especially easy (finally: blocks are the
biggest problem).
Cheers,
mwh
--
I really hope there's a catastrophic bug in some future e-mail
program where if you try and send an attachment it cancels your
ISP account, deletes your harddrive, and pisses in your coffee
-- Adam Rixey
More information about the Python-list
mailing list