Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
resetting a generator
#9
what my first thought was: the main loop of my generator consisting of a block where the yield statement would be found, would have other code that checks the reset flag and if that flag is up, do a reset block of code that lowers the flag and updates variables to reflect the reset state so the yield statement below it will yield the first item, again. the hard part is if the generator has already ended, which i presume has raised StopIteration. what i am curious about is: if you have an iterator driven loop where a generator is the iterator, does StopIteration get raised before or after the last pass of the body of the loop. i can imagine either scenario, so that does not confine the knowledge for me. it is in that body where the reset could be done, not after it. so if the scenario is to raise StopIteration after the last pass (which would not run that block, again), i think this could be done, because the iteration mechanism does not know it is the last pass during the last pass, so a reset during the "last" pass could make the generator still yield values for even more passes. the big worry is that it might be running the last pass after StopIteration has been raised, which probably cannot be undone.

(Nov-13-2019, 06:13 AM)Gribouillis Wrote: To learn about it, you could start with this page by David Beazley.

i dislike the way his source code operates on his web site. it forces the source to be downloaded and does not allow me to choose to just view it (as my site does).

[i used "dislike" instead of the 4-letter "h"-word since this is a family-oriented forum.]
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
resetting a generator - by Skaperen - Nov-09-2019, 06:07 AM
RE: resetting a generator - by Gribouillis - Nov-10-2019, 04:21 PM
RE: resetting a generator - by Skaperen - Nov-10-2019, 08:36 PM
RE: resetting a generator - by Gribouillis - Nov-10-2019, 08:50 PM
RE: resetting a generator - by Skaperen - Nov-12-2019, 09:44 PM
RE: resetting a generator - by Gribouillis - Nov-12-2019, 10:37 PM
RE: resetting a generator - by Skaperen - Nov-13-2019, 04:44 AM
RE: resetting a generator - by Gribouillis - Nov-13-2019, 06:13 AM
RE: resetting a generator - by Skaperen - Nov-14-2019, 04:09 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020