[python] "UnboundLocalError: local variable referenced before assignment" after an if statement