I am trying to implement insert function here. Well, for this class Matrix which is the child class of Grid, seem to have problem. But I don't quite understand what I am doing wrong here. The error says " Grid[m][n] = value TypeError: 'type' object is not subscriptable."
Please help
thanks
from Grid import Grid
class Matrix(Grid):
def __init__(self, m, n, value=None):
## super(Matrix, self).__init__(m, n)
Grid.__init__(self, m, n)
def insert(self, m, n, value=None):
Grid[m][n] = value
here is Grid class
from CArray import Array
class Grid(object):
"""Represents a two-dimensional array."""
def __init__(self, rows, columns, fillValue = None):
self._data = Array(rows)
for row in xrange(rows):
self._data[row] = Array(columns, fillValue)
def getHeight(self):
"""Returns the number of rows."""
return len(self._data)
def getWidth(self):
"Returns the number of columns."""
return len(self._data[0])
def __getitem__(self, index):
"""Supports two-dimensional indexing
with [row][column]."""
return self._data[index]
def __str__(self):
"""Returns a string representation of the grid."""
result = ""
for row in xrange(self.getHeight()):
for col in xrange(self.getWidth()):
result += str(self._data[row][col]) + " "
result += "\n"
return result