Thanks for all the suggestions.
I replaced the recursive control() calls with return control() and the final else clause with return None. However it still hit the return None then jumped up to some of the return control()s as opposed to fnishing.
Instead, I've put an ugly bodge job in the function that was causing the error, so the unwanted behaviour is still there, but is now harmless. At least for my test cases, which...
User Profile
Collapse
-
Hi, thanks for the quick reply. My code is processing some XML (specifically MathML) which is represented by a lxml doc tree. Here's a piece of my code, with a couple of examples of the recursive calls that seem to be doing me no favours.
[CODE=python]
def control():
if wanted_list: #if a global list is populated
wanted_variable = wanted_list[-1]
if wanted_variable in Glob_Vars:...Leave a comment:
-
Getting out of a recursive function...
Hi,
I have a function, looks a bit like this:
def function():if condition:do stuff, including a few recursive calls (to function()),
this 'stuff' also changes the state of 'condition'.
'condition' is a global list.else:I want to break out of the function and move on
To break out I have tried just sticking a return in the else clause, I've also tried raising an exception...
No activity results to display
Show More
Leave a comment: