Python Forum
Nesting loops more than 20 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Nesting loops more than 20 (/thread-13230.html)



Nesting loops more than 20 - RtjShreyD - Oct-05-2018

I am upto creating a lookup table for a Human modelling software, Makehuman I have to translate its scale into real world metric scale for that I am creating lookup tables. It has 25 parameters that needs to be varied, I am using 25 nested for loops for that and store values finally in database SQlite .
Initially I got an exception: Too many statically nested blocks.
So to solve it I made a function for loop 2 to loop 19 and ran the code, I did not get the exception but my system got hanged when it was just computing the 11th loop.
Then I breaked the loop in even more parts, so it ran the whole code but the result in the database was not as I wanted ie, for every loop that was replaced by a function it was not computing it for all the values I wanted. I am sharing the links to my code please have a look and tell me how can I modify them.
https://github.com/RtjShreyD/Playing-with-Makehuman-scripts/blob/master/works4.py -->This clearly shows what I want to do.
https://github.com/RtjShreyD/Playing-with-Makehuman-scripts/blob/master/works5.py --->This hangs my system.
https://github.com/RtjShreyD/Playing-with-Makehuman-scripts/blob/master/works6.py --->This does not give correct result in the database.

Please advise what can be done. **geek**


RE: Nesting loops more than 20 - Mekire - Oct-05-2018

(Oct-05-2018, 07:28 AM)RtjShreyD Wrote: It has 25 parameters that needs to be varied, I am using 25 nested for loops for that and store values finally in database SQlite .
No offense intended, but there is absolutely no way that this is the best way (or even a remotely acceptable way) to do this.

For starters I would suggest looking at the itertools library. You should be able to do something like generate all permutations of the needed variables and go from there.


RE: Nesting loops more than 20 - Larz60+ - Oct-05-2018

Yikes! this hurts my eyes!