python unboundlocalerror referenced before assignment