What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

Joshua Landau joshua.landau.ws at gmail.com
Mon Jun 24 16:33:19 EDT 2013


On 24 June 2013 21:12, John Gordon <gordon at panix.com> wrote:
> Since you're new to programming, this might be a bit tricky to explain,
> but I'll do my best. :-)
>
> The problem is that change() isn't being executed here; instead it's being
> executed from within root.mainloop(), whenever the user presses button-1.
>
> And within root.mainloop(), there is no variable called isWhite.

Sorry, but I don't think you're right. Functions "carry" their
contexts around with them, so that shouldn't matter

(See Peter and Antoon's comments for explanation of what I think it is)



More information about the Python-list mailing list