A RetroSearch Logo

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

Search Query:

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

[Python-Dev] just trying to catch up with the semantic

[Python-Dev] just trying to catch up with the semanticGuido van Rossum guido@digicool.com
Thu, 01 Mar 2001 15:46:56 -0500
> is the semantic (expressed through bytecode instrs) right?

Hi Samuele,

Thanks for bringing this up.  I agree with your predictions for these
examples, and have checked them in as part of the test_scope.py test
suite.  Fortunately Jeremy's code passes the test!

The rule is really pretty simple if you look at it through the right
glasses:

    To resolve a name, search from the inside out for either a scope
    that contains a global statement for that name, or a scope that
    contains a definition for that name (or both).

Thus, on the one hand the effect of a global statement is restricted
to the current scope, excluding nested scopes:

   def f():
       global x
       def g():
           x = 1 # new local

On the other hand, a name mentioned a global hides outer definitions
of the same name, and thus has an effect on nested scopes:

    def f():
       x = 1
       def g():
           global x
           def h():
               return x # global

We shouldn't code like this, but it's good to agree on what it should
mean when encountered!

--Guido van Rossum (home page: http://www.python.org/~guido/)



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