How to get one value at a time from a generator function in Python?

bodacydo picture bodacydo · Mar 10, 2010 · Viewed 73.1k times · Source

Very basic question - how to get one value from a generator in Python?

So far I found I can get one by writing gen.next(). I just want to make sure this is the right way?

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Mar 10, 2010

Yes, or next(gen) in 2.6+.