Error "variable local referenced before assignment"

0

I have two apparently equivalent variables. One works well, the other gives me the famous error:

  

local variable referenced before assignment

Partial code:

from kivy.app import App
from kivy.uix.relativelayout import RelativeLayout

global_layout = RelativeLayout(size = (800, 550))

initial_castle_values = ((1, 1), (1, 1))
initial_board = ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                (0, 4, 1, 0, 0, 0, 0, -1, -4, 0),
                (0, 2, 1, 0, 0, 0, 0, -1, -2, 0),
                (0, 3, 1, 0, 0, 0, 0, -1, -3, 0),
                (0, 5, 1, 0, 0, 0, 0, -1, -5, 0),
                (0, 6, 1, 0, 0, 0, 0, -1, -6, 0),
                (0, 3, 1, 0, 0, 0, 0, -1, -3, 0),
                (0, 2, 1, 0, 0, 0, 0, -1, -2, 0),
                (0, 4, 1, 0, 0, 0, 0, -1, -4, 0),
                (0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

castle_values = [[int for i in range(2)] for j in range(2)]
value_board = [[int for i in range(10)] for j in range(10)]

def whatiswrong():
    print(value_board)
    print(castle_values)

def assign_button_board(v_board):
    print("assign button board")
    for i in range(10):
        for j in range (10):
            value_board[i][j] = v_board[i][j]

def assign_button_castle(v_castle_values):
    print("assign button castle")
    for i in range(2):
        for j in range(2):
            castle_values[i][j] = v_castle_values[i][j]

class JFKKApp(App):
    def build(self):
        print("build")
        assign_button_board(initial_board)
        assign_button_castle(initial_castle_values)
        whatiswrong()
        return global_layout

if __name__ == "__main__":
    JFKKApp().run()

This works fine, but if I convert whatiswrong() into callback () and call it from a Button, the first variable is painted correctly and the second tells me it is not assigned ( local variable 'castle_values' referenced before assignment ).

Why?

    
asked by user111799 17.12.2018 в 16:50
source

0 answers