Silly title, and I know a bit more Math then Computer Science (in fact I am a poor programmer). In my Python program - code below -I have an error message saying I have too many nested static blocks. It looks as if Python got stubborn on the 21st for.

Can anyone point me to a language where I can manage this (or how I might get Python to accomplish what I want)?

NOTE: Each adjran[ aj] and each incloneinv[imageone[aj]] is a two or three element set that depends on the elements selected in the previous two lines. (The message system does not show the indentation)

A0 = [0,1,2,3,4,5,6,7,8,9]     

for a0 in A0:
 for b0 in incloneinv[imageone[a0]]:
  for a1 in adjran[a0]:
   for b1 in adjran[b0] & incloneinv[imageone[a1]]: 
    for a4 in adjran[a1]:
     for b4 in adjran[b1] & incloneinv[imageone[a4]]:
      for a7 in adjran[a4]:
       for b7 in adjran[b4] & incloneinv[imageone[a7]]: 
        for a10 in adjran[a7]:
         for b10 in adjran[b7] & incloneinv[imageone[a10]]:
          for a13 in adjran[a10]:
           for b13 in adjran[b10] & incloneinv[imageone[a13]]: 
            for a16 in adjran[a13]:
             for b16 in adjran[b13] & incloneinv[imageone[a16]]:

              for a2 in adjran[a0]:
               for b2 in adjran[b0] & incloneinv[imageone[a2]]: 
                for a5 in adjran[a2]:
                 for b5 in adjran[b2] & incloneinv[imageone[a5]]:
                  for a8 in adjran[a5]:
                   for b8 in adjran[b5] & incloneinv[imageone[a8]]: 
                    for a11 in adjran[a8]:
                     for b11 in adjran[b8] & incloneinv[imageone[a11]]:
                      for a14 in adjran[a11]:
                       for b14 in adjran[b11] & incloneinv[imageone[a14]]: 
                        for a17 in adjran[a14]:
                         for b17 in adjran[b14] & incloneinv[imageone[a17]]:

                          for a3 in adjran[a0]:
                           for b3 in adjran[b0] & incloneinv[imageone[a3]]: 
                            for a6 in adjran[a3]:
                             for b6 in adjran[b3] & incloneinv[imageone[a6]]:
                              for a9 in adjran[a6]:
                               for b9 in adjran[b6] & incloneinv[imageone[a9]]: 
                                for a12 in adjran[a9]:
                                 for b12 in adjran[b9] & incloneinv[imageone[a12]]:
                                  for a15 in adjran[a12]:
                                   for b15 in adjran[b12] & incloneinv[imageone[a15]]: 
                                    for a18 in adjran[a15]:
                                     for b18 in adjran[b15] & incloneinv[imageone[a18]]:

                                        print ' '
                                        print ' ' , a1, a4, a7, a10, a13, a16 , ' now b  ' , ' ', b1, b4, b7, b10, b13, b16
                                        print   a0, a2, a5, a8, a11, a14, a17 , ' now b  ' ,  b0, b2, b5, b8, b11, b14, b17
                                        print ' ' , a3, a6, a9, a12, a15, a18 , ' now b  ' , ' ', b3, b6, b9, b12, b15, b18
                                        print ' '

Edit: Added code tags ... vegaseat

11 Years
Discussion Span
Last Post by alc6379

I asked some of our friends in the C/C++ Forum at DaniWeb and it looks like ANSI C limits the level of nesting to 15, some compilers a little more. The Python interpreter DLL is written in ANSI C. The standard C++ compiler may have a higher limit of nesting, needs to be tested though!


>I asked some of our friends in the C/C++ Forum at DaniWeb
Who gave you the answer you asked for but not the answer you were looking for. C's nesting limit has nothing to do with Python's nesting limit. But the cold hard fact of the matter is that Python limits static nesting to 20 levels. Break that ugly ass mess of loops up into a few functions with more reasonable nesting.


Original question by bobpierce01 on nesting levels ...

Can anyone point me to a language where I can manage this (or how I might get Python to accomplish what I want)?

C89 has 15 levels, C99 has 127 levels and C++ has 256 levels. The creators of Python most likely picked 20 levels of nesting (mildly more than ANSI C) for performance reasons.

You could write your program in C++ or break up the nesting with function calls that contain some of the nesting.

Thanks are due to narue for the additional details.


I'm not even a real programmer, but I'd have to agree with Narue-- there HAS to be some way to use recursion, or someting to break that up. With what little I know, that just doesn't look very "elegant", or reusable, for that matter.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.