User Profile

Collapse

Profile Sidebar

Collapse
nathanM
nathanM
Last Activity: Apr 21 '08, 11:32 PM
Joined: Mar 25 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • nathanM
    replied to Getting out of a recursive function...
    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...
    See more | Go to post

    Leave a comment:


  • nathanM
    replied to Getting out of a recursive function...
    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:...
    See more | Go to post

    Leave a comment:


  • nathanM
    started a topic Getting out of a recursive function...

    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...
    See more | Go to post
No activity results to display
Show More
Working...