所以我有两个用户定义的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
提交
取消