explicit variable scoping

Eyal Lotem gnupeaker at yahoo.com
Tue Mar 23 15:26:28 CET 2004

--- Jacek Generowicz <jacek.generowicz at cern.ch> wrote:
> Actually, I think that "referencing" works fine as
> it is. The problem
> is that "setting" (at the moment) can either be
> "creating a new binding" or "rebinding an existing
> All this can be achieved by the simple expedient of
> distinguishing
> binding and re-binding. (Though I have no truly
> convincing suggestion
> of how this distinction should be spelt in Python.)

One of the main things I am after, is eliminating the
heuristic by which Python "guesses" whether a variable
is global/local, according to whether any assignment
was seen.  This confuses novices and annoys experts
that stumble upon it, and it is definitely a problem.

If explicit differentation between new bindings and
rebindings solves that, I'm all for it.

I have only recently noticed that when calling the
module's functions, or when using imported modules,
and perhaps in many other cases, you don't typically
want to have to explicitly name the global scope and
thus I take back my "global" syntax suggestion.

Explicit "let"s do seem to get rid of the
local-vs-global issue, while providing an elegant
solution to the nested-functions variable access

def f():
  def a=None,b=3 # Since locals are typically
                 # created via an assignment
                 # it makes much sense to allow
                 # unifying the creation of their
                 # scope [def] with the assignment
                 # to eliminate some redundancy
  b=4 # rebinding
  d=5 # raise error, neither local or global
  global e
  def g():
    e=10 # global assignment
    b=5 # rebinding
    def a=7 # new local binding
  print a, b, e # will print None, 5, 10

Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.

More information about the Python-list mailing list