This is my first class. I've been working a while on it, some functions are future ideas and are right now just bare bones and intended to be worked on later. I'm really looking for a good review of what I have so far, I've never done this before so hopefully I'm off to a decent start. I tried to log my errors as well and handle them by skipping but annotating which values are trouble. Also first time using *args in my functions.
class Matrix():
def __init__(self, height, width):
self.rows = [[0]*width for i in range(height)]
self.height = height
self.width = width
def __str__(self):
s = "\n" + "\n".join([str(i) for i in [rows for rows in self.rows] ]) + "\n"
return s
def __repr__(self):
return (f'{self.__class__.__name__} ({self.height!r} , {self.width!r})')
def len(self):
return self.height * self.width
def __add__(self, matrix2):
return
def __mul__(self, matrix2):
return
def remove(self, item):
return
def fill_matrix(self, fill_list):
index = 0
for i in range(len(self.rows)):
try:
for j in range(len(self.rows[i])):
self.rows[i][j] = fill_list[index]
index += 1
except IndexError:
print (f"Matrix not filled \nMatrix fill stopped at: row {i}, Column {j}")
break
return fill_list[index:]
def add_value(self, *args):
log = []
for arg in args:
try:
arg_size = len(arg)
except TypeError:
log.append(f'Parameter must be sequence, skipped: {arg}')
continue
try:
if arg_size == 3:
self.rows[arg[0]] [arg[1]] = arg[2]
else:
log.append(f'Parameter has too little or too much data, skipped: {arg}')
except IndexError:
log.append(f'Location parameters are out of range, skipped: {arg}')
except TypeError:
log.append(f'Location indicies must contain integral types, skipped: {arg}')
return log
myMat = Matrix(5,5)
overflow = myMat.fill_matrix([i for i in range(26)])
print(myMat)
Errors = myMat.add_value((-1,3,500), (0,0,3),(51,5, 7), (1, 2, 667), [3,4,676], (1), (1,"a", 1), (1,1, "£"))
print(myMat)