Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)

Paul Rubin http
Sat Aug 6 20:42:31 EDT 2005

Mike Meyer <mwm at> writes:
> You can't "fix" this. This code (in some python-like langauge that
> isn't python):
> x = 23
> def fun():
>     x = 25
>     # Rest of code
> has two possible interpretations.

The fix is to add a "local" declaration in "fun":

   local x = 25

for example.  If you want the one from the outer scope, then use, perhaps,

  outer x = 25

One really screwy situation with Python is

    x = 23
    def f():
      x = 25
      def g():
        x += 3

g obviously is supposed to inherit x from the surrounding scope, but
there's no way for g to actually change x.

More information about the Python-list mailing list