Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Python属性错误';地图';对象没有属性';单元格';_Java_Python - Fatal编程技术网

Java Python属性错误';地图';对象没有属性';单元格';

Java 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.

我试图将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.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)]