Java Python属性错误';地图';对象没有属性';单元格';
我试图将java代码翻译成Python,但遇到了一个attributenotfound错误 以下是有效的java代码: javaJava Python属性错误';地图';对象没有属性';单元格';,java,python,Java,Python,我试图将java代码翻译成Python,但遇到了一个attributenotfound错误 以下是有效的java代码: java public class Map { private Cell[][] cells; public Map() { this.cells = new Cell[7][7]; for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { this.
public class Map {
private Cell[][] cells;
public Map() {
this.cells = new Cell[7][7];
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
this.cells[i][j] = new Cell();
}
}
}
}
下面是我的Python代码,其中有错误:
Map.py
from Cell import Cell
class Map():
def __init__(self):
for i in range(7):
for j in range(7):
self.cells[i][j] = Cell()
Cell.py
class Cell():
def __init__(self):
self.occupiedObject = None
我想你想要这样的东西:
class Cell:
def __init__(self):
self.occupied_object = None
class Map:
def __init__(self):
self.cells = [[Cell() for x in range(7)] for y in range(7)]
class Cell:
def __init__(self):
self.occupied_object = None
class Map:
def __init__(self):
self.cells = [[Cell() for x in range(7)] for y in range(7)]