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/2003-October/039400.html below:

[Python-Dev] Re: closure semantics

[Python-Dev] Re: closure semanticsSkip Montanaro skip at pobox.com
Thu Oct 23 17:46:33 EDT 2003
    John> How about (to abuse a keyword that's gone unmolested for too long)

    John>    global foo from def

    John> to declare that foo refers a variable in a lexically enclosing
    John> function definition?  This avoids to need to name a specific
    John> function (which IMHO is just a source of confusion over the
    John> semantics of strange cases) while still having some mnemonic value
    John> (foo "comes from" an enclosing function definition).

How do you indicate the particular scope to which foo will be bound (there
can be many lexically enclosing function definitions)?  Using my example
again:

    def outer(a):
        x = a
        def inner(a):
            x = 42
            def innermost(r):
                global x from def       # <--- your notation
                x = r
            print "  inner, x @ start:", x
            innermost(random.random())
            print "  inner, x @ end:", x
        print "outer, x @ start:", x
        inner(a)
        print "outer, x @ end:", x

how do you tell Python that x inside innermost is to be associated with the
x in inner or the x in outer?

Skip

More information about the Python-Dev mailing list

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