What's up with rebinding assignment?

Michael Chermside mcherm at mcherm.com
Thu Mar 27 18:16:58 CET 2003

Greg Ewing writes:
> > def bind():
> >     x = 1
> >     def rebind():
> >         lexical x
> >         x = 2
> >     rebind()
> >     print x
> This looks a lot neater to me than adding a new assignment
> operator.


> But I would call it "outer" rather than "lexical".


I'm not yet convinced that allowing this is a good idea -- I
rarely need it and tend to use classes as a workaround in the
rare cases. But IF it's to be done, this feels like the "one
obvious way".

It would certainly clear up an oddity about scopes. Right now
we have:
     global (module level)
     "outer" (nested scopes)

All are readable. built-in is not writable (except with tricks)
on purpose. Global is writable only with global statement.
local is writable always (of course!). But "outer" seems the
odd man out.

Why-don't-we-just-eliminate-the-global-statement-instead 'lly

-- Michael Chermside

More information about the Python-list mailing list