Nested Scopes in Idle/PythonWin

Greg Chapman glc at well.com
Sun Apr 22 15:51:13 EDT 2001


On Sun, 22 Apr 2001 15:27:47 -0400 (EDT), Jeremy Hylton wrote:
>
> You didn't tell the interpreter that you wanted to use nested scopes.
>
> >>> from __future__ import nested_scopes
> >>> def make_adder(x):
> ...	  return lambda y: x + y ...
> >>>
> >>>

Actually, that was one of the first things I tried.  It doesn't work under
Idle.  I believe the above result is from the python program itself in
interactive mode (that does work for me).  But here's what I get using Idle
(PythonWin generates a similar SyntaxWarning):

Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> from __future__ import nested_scopes
>>> def make_adder(x):
	return lambda y: x+y
SyntaxError: local name 'x' in 'make_adder' shadows use of 'x' as global in
nested scope 'lambda' (<pyshell#2>, line 1)
>>>

Greg





More information about the Python-list mailing list