A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-March/013636.html below:

[Python-Dev] Simple generator implementation

[Python-Dev] Simple generator implementationNeil Schemenauer nas@arctrix.com
Fri, 16 Mar 2001 05:54:48 -0800
On Fri, Mar 16, 2001 at 03:37:33AM -0800, Neil Schemenauer wrote:
> ... it looks like it would be similer to put this code in the
> switch statement.

Um, no.  Bad idea.  Even if I could restructure the loop, try/finally
blocks mess everything up anyhow.

After searching through many megabytes of python-dev archives (grepmail
is my friend), I finally found the posts Tim was referring me to
(Subject: Generator details, Date: July 1999).  Guido and Tim already
had the answer for me.  Now:

    import sys

    def g():
        for n in range(10):
            suspend n, sys._getframe()
        return None, None

    n, frame = g()
    while frame:
        print n
        n, frame = frame.resume()

merrily prints 0 to 9 on stdout.  Whee!

  Neil



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4