<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 20 January 2014 10:47, Julian Taylor <span dir="ltr"><<a href="mailto:jtaylor.debian@googlemail.com" target="_blank">jtaylor.debian@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">how can an import that is never called cause an unbound name error?</blockquote></div><br></div><div class="gmail_extra">
When Python code is compiled, references to variables defined within the function have a different lookup path to global variables (a LOAD_FAST bytecode vs LOAD_GLOBAL). If a variable is defined anywhere within that function, it is considered local, and you cannot look it up globally. This is a classic gotcha:<br>
<br>a = 0<br>def f():<br> a = a + 1<br>f() # UnboundLocalError<br><br></div><div class="gmail_extra">Thomas<br></div></div>