I have an application where i use three generators. There are multiple devices which will get assigned with directories of files contained in them.
So, in the top level, I have a list of devices, I iterate each device and pick up allocated directories for it in a generator. In this directories generator I again have a file iterator (files contained in each allocated directory).
There are two generators, one for directory level the other for file level.
Can I limit the number of files I return in the device level generator.
For instance, in the first iteration it should yield 10 files in round robin fashion. After 10 items, it should stop iteration. Next turn, fetch 10 more items and stop iteration and so on until it completes all items in all directories for all devices.
All generators are written in python using __iter__
and __next__
methods.
Will it be possible to limit the number of items yielded by these generators?