PEP 318

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Mar 23 22:50:07 CET 2004


> From: Skip Montanaro
> 
> You'll be free to write your generator functions like so:
> 
>     def generator(f):
>         return f
> 
>     def silly_counter(n) [generator]:
>         for i in range(10):
>             yield n+i

Ooh - I hadn't thought of that one Skip. I like it.

Of course, rather than just passing the function through, I'd probably want to check that it was actually a generator.

    def generator (f):
        assert f.func_code.co_flags & 0x20
        return f

    def silly_counter(n) [generator]:
        for i in range(10):
            yield n+i

Tim Delaney




More information about the Python-list mailing list