If just got confronted with a weird issue in a program of mine. If simplified my code to the following:
def x(y="test"):
def xx():
if False:
y = "blubb"
print y
xx()
print y
x()
This throws the UnboundLocalError: referenced before assignment Error.
If i fix the code to the following:
def x(y="test"):
def xx():
print y
xx()
print y
x()
My code works again. I'm on Python 2.7. I've just figured out, that the follow fix work as well and this is how i'm going to fix my software for the moment:
def x(y="test"):
def xx():
_y = y
if False:
_y = "blubb"
print _y
xx()
print y
x()