<div dir="ltr"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I think you are making an unwarranted assumption about what is &quot;more expected&quot;. I presume you are thinking that the expected behaviour is that foo() should:<br>


<br>
print global x (5)<br>
assign 1 to local x<br>
print local x (1)<br>
<br>
If we implemented this change, there would be no more questions about UnboundLocalError, but instead there would be lots of questions like &quot;why is it that globals revert to their old value after I change them in a function?&quot;.<br>

</blockquote></div><br>True, but this is less confusing and follows the rules in a more straightforward way. x = 1 without a &#39;global x&#39; assigns a local x, this make sense and is similar to what happens in C where an inner declaration temporarily shadows a global one.<br>

<br>Eli<br></div>