[Greg Chapman] > No, I'm talking about the interactive interpreter: > > 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 > >>> 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#1>, line 1) [Jeremy Hylton] > 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 > ... > >>> Greg is using IDLE, not a cmdline Python, and it doesn't work in IDLE. This has been listed as an unresolved issue in PEP 236 all along: Unresolved Problem: Simulated Interactive Shells Interactive shells "built by hand" (by tools such as IDLE and Emacs Python-mode) should behave like native interactive shells (see above). However, the machinery used internally by native interactive shells has not been exposed, and there isn't a clear way for tools building their own interactive shells to achieve the desired behavior. That's still the case (else I would have updated the PEP to say something else there <wink>).
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