2.2 features

Tom Good Tom_Good1 at excite.com
Mon Jul 23 14:25:00 EDT 2001


"Nick Perkins" <nperkins7 at home.com> wrote in message news:<gER67.534750$eK2.111982758 at news4.rdc1.on.home.com>...
> I can't believe the quantity of discussion (still) going on over the div
> thing!
> 
> And meanwhile, 2.2a1 is out, and there are far more interesting things
> happening to our little language.
> 
> Isn't there anything in 2.2 that deserves even a fraction of the discussion
> going on about div? (which has been beaten to death 9 times)
> 
> getset(), staticmethod(), classmethod(), etc...
> 
> How about generators, who's tried them out?

[snip]

I like generators a lot.  Here's a fun one:

#------ begin code
from __future__ import generators

def fib():
    "unbounded generator, creates Fibonacci sequence"
    x = 0
    y = 1
    while 1:
        x, y = y, x + y
        yield x

if __name__ == "__main__":
    g = fib()
    for i in range(9):
        print g.next(),

#------ end code

c:\python22>python fib.py
1 1 2 3 5 8 13 21 34


Tom



More information about the Python-list mailing list