I’ve a part of my python program which is generated, the generated codes contains a lot of nested if / else, my problem is that a lot can be too much and I got this Error when running my code:
IndentationError: too many levels of indentation
I’ve read that this was some limitation defined on the low level of the python interpreter, does anybody know how I can find a workaround for it? Some interpreter parameters would be fine, the only solution proposal I’ve found suggests to recompile Python in order to set a different value for the MAXINDENT constant, which is not exactly what I’m dreaming of.
EDIT : The code is a big bunch of nested if...else , it’s dirty but it was the quickest I found to port a complex decision tree to Python. I know how dirty it is; I did not write it myself — I did not even plan to edit it (I would rather touch the generator).
I know I can modelize this decision tree in other fashions. What I would like is a way simpler than that, like tweaking the interpretor if possible.
EDIT 2 : Now I’ve done some refactoring, and my tree is stored as a dictionary: The loading of the file gives a new error :
s_push: parser stack overflow
MemoryError
Here again I found a resource suggesting some tweaks of the interpreter’s headers.
You can have deeply nested structures that are generated dynamically e.g., ~100 nested-levels list leads to
s_push: parser stack overflowas a string literal but it works if you create it dynamically from json-text, example: