[IPython-dev] paste magic command not working
Thomas Kluyver
takowl at gmail.com
Mon Jan 20 18:05:54 EST 2014
On 20 January 2014 10:47, Julian Taylor <jtaylor.debian at googlemail.com>wrote:
> how can an import that is never called cause an unbound name error?
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:
a = 0
def f():
a = a + 1
f() # UnboundLocalError
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140120/868d413b/attachment.html>
More information about the IPython-dev
mailing list