+ 1
Reset Generator
What is the proper way to reset a generator, such as if you want to reuse the same generator in two separate areas of your code? ... please assume that combining those two separate uses into one is not feasible/desired.
2 odpowiedzi
+ 7
It seems you can use itertools.tee() to make a second version of the generator:
y = FunctionWithYield()
y, y_backup = tee(y)
for x in y:
print(x)
for x in y_backup:
print(x)
from https://stackoverflow.com/q/1271320
+ 2
Thanks!