所以我有兩個用戶定義的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 = colorclass 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現在我有一個名為單元格的2-D列表 它被定義并看起來像這樣 點擊我。它有點混亂,但你可以看到它是一個16×16的矩陣,存儲一個對象od單元格,如上定義。不,我想將此2-D數組存儲在json文件中,這就是我正在做的事情json_data = []json_data.append(cells)with open("default.json" , "w") as f: json.dump(json_data,f,indent = 2)
添加回答
舉報
0/150
提交
取消