[issue35069] Unexecuted import in function causes UnboundLocalError

Steven D'Aprano report at bugs.python.org
Thu Oct 25 16:32:45 EDT 2018


Steven D'Aprano <steve+python at pearwood.info> added the comment:

Yes, that's exactly right. That's how local variables work in Python:

x = 999  # global x
def demo():
   if False:
       x = 1
   x  # local x has no value

does the same thing. This is standard, documented behaviour, regardless 
of which kind of assignment statement you use.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35069>
_______________________________________


More information about the Python-bugs-list mailing list