Possible Duplicate:
How to clone a Python generator object?
Suppose I have a generator 'stuff_to_try', I can try them one by one but if I had a method that wanted to go through the generator and that method is recursive, I want to let each recursion get a fresh new generator that starts at the first yield rather than where the last recursion left off.
def solve(something):
if exit_condition(something):
return
next_to_try = stuff_to_try.next()
while not if_works(next_to_try):
next_to_try = stuff_to_try.next()
solve(do_something(something))
Of course I can define stuff_to_try inside the recursive function but is there a better way? Is there an equivalent of stuff_to_try.clone().reset() or something?