This is because you call the generator each time, starting it again.
Here is the fixed version:
dates = gettime(nextdate) for i in range(0, 25): print dates.next()
This gives me:
2011-08-22 11:00:00 2011-08-22 11:15:00 2011-08-22 11:30:00 2011-08-22 11:45:00 ...etc.
It is important to remember that the yield function actually returns a generator , as you can see when we look at my dates object:
>>> dates <generator object gettime at 0x02A05710>
This is what you can call next() on repeatedly to get the next value. Each time you execute your cycle, you create a completely new generator and get the following (in this case, the first) value from it.
source share