Python Forum
iterating an iterator by one step
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iterating an iterator by one step
#1
i have a loop that is going through every file in a directory tree, doing a conversion on each, then moving that file to another directory tree. another process can add files to this directory tree at any time. so, each time this loop runs i need to get the the first file from the tree, waiting a minute if the tree is empty (until a stop flag exists in another location).

i have a generator that delivers every file in the tree when iterated.

does it make sense, that loop, to make a new generator each time and just call next() one time each instead of iterating through the directory tree?

something like:
while True:
   afile=next(mygen(thetree))
   ...
does it make sense to "iterate" an iterator just once like that?
Tradition is peer pressure from dead people

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  testing if an iterator is empty Skaperen 9 9,209 Feb-25-2022, 02:31 AM
Last Post: Skaperen
  multiplying an iterator Skaperen 9 3,339 Oct-12-2021, 07:07 PM
Last Post: Skaperen
  modifying the origin of an iterator Skaperen 4 2,994 Mar-05-2020, 11:49 PM
Last Post: Skaperen
  Can anyone recommend a step by step guide to building an app PyNovice 9 3,925 Sep-16-2019, 03:53 PM
Last Post: PyNovice

Forum Jump:

User Panel Messages

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