This post proposes the answer to a question I've had for years, namely, how 
to see what a generator is doing "while the generator is doing it" :-)

A long time ago, in a thread far away (no idea where), I asked Guido this 
question and he was stumped.  Iirc, we were both looking for the answer 
somewhere like in python's itertools 
<https://docs.python.org/3/library/itertools.html>module.

But during the recent rewrite of the TokenOrderGenerator class (in 
leoAst.py), I suddenly saw a dirt simple answer. If I want to "capture" and 
"restart" a generator, just do something like this:

captured_list = list(yield whatever)  # or "yield from"
yield from captured_list

To be clear, this is for debugging only. Calling list negates most of the 
advantages of having a generator, but for debugging we don't care.

I haven't tested this idea, but it smells like the solution.

What do you think?

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/a5572d2c-4f9b-40b2-b339-7fff6fdf3e63n%40googlegroups.com.

Reply via email to