-2

したがって、以下に示す2つのユーザー定義のpythonクラスがあります

class cell(object):
def __init__(self,id,x_cor,y_cor,width = cell_size,height = cell_size ,color = lightblue ):
    self.id = id
    self.x_cor = x_cor
    self.y_cor = y_cor
    self.width = width
    self.height = height
    self.color = color

class edge(object):
def __init__(self,pos, x_cor,y_cor,state,color = lightgreen):
    global border_size
    global cell_size
    self.pos = pos
    self.x_cor = x_cor
    self.y_cor = y_cor
    self.state = state
    self.color = color
    if self.state == "H":
        self.width = cell_size+(border_size)*2
        self.height = border_size
        self.x_lower_bound = self.x_cor + border_size
        self.x_upper_bound = self.x_cor +border_size+ cell_size
        self.y_lower_bound = self.y_cor
        self.y_upper_bound = self.y_cor + border_size
    elif self.state == "V":
        self.width = border_size
        self.height = cell_size+(border_size*2)
        self.x_lower_bound = self.x_cor
        self.x_upper_bound = self.x_cor + border_size
        self.y_lower_bound = self.y_cor + border_size
        self.y_upper_bound = self.y_cor + border_size + cell_size

これで、cells という 2-D リストが作成されました。これは次のように定義されており、クリックしてください。

少し乱雑ですが、上記で定義したオブジェクト od セルを格納する 16 x 16 のマトリックスであることがわかります。

いいえ、この 2 次元配列を json ファイルに保存したいのですが、これが私がやっていることです

json_data = []
json_data.append(cells)
with open("default.json" , "w") as f:
    json.dump(json_data,f,indent = 2)

これは、私が取得している端末のエラーです リンクをクリックして表示します

4

1 に答える 1