Thursday, May 7, 2009

March 2 - 6

We're STILL reading that wonderful DB design book this week. On a happier note, I've learned about another nifty little gem in the language of Python this week's examples. We looked at Python generator types(amongst other things). Similar to my last post, using Python Generators gives another type of persistent storage for the function. Take a look at this example:

def f (b, e) :
while b < e :
yield b
b += 1

This simple function generates all the integers in the range [b, e). This "yield" machinery seems to function like a sort of stored program counter for the function. Each time the generator is prompted for the next value, the program counter resumes where it left off.

No comments:

Post a Comment