IDLE being too clever checking nonlocal declarations?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Oct 21 19:52:54 EDT 2013


On Mon, 21 Oct 2013 15:51:56 -0400, Terry Reedy wrote:

> On 10/21/2013 11:06 AM, Chris Angelico wrote:
>> Try typing this into IDLE:
>>
>>>>> def a():
>>      def b():
>>          nonlocal q
>> SyntaxError: no binding for nonlocal 'q' found
> 
> If you submit those three lines to Python from the command line, that is
> what you see.

Arguably, that's also too strict, but these *four* lines work fine 
interactively:

py> def a():
...     def b():
...             nonlocal q
...     q = 1
...


and also from the command line:


[steve at ando ~]$ python3.3 -c "def a():
>     def b():
>         nonlocal q
>     q = 1
> "


so it should also work in IDLE.




-- 
Steven



More information about the Python-list mailing list