IDLE being too clever checking nonlocal declarations?

C

Chris Angelico

Try typing this into IDLE:
def b():
nonlocal q
SyntaxError: no binding for nonlocal 'q' found


In interactive command-line Python, this doesn't throw an error, and
it works fine if the name is used later:
def b():
nonlocal q
q+=1
q=1
b()
return q
2

But typing this into IDLE interactive mode requires some fiddling
around with the editor. Is it trying to be too clever? Am I doing
something that makes no sense?

Tested with 3.3.0 on Windows XP.

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top