Nekiruhs
October 18th, 2007, 01:03 AM
For the sake of learing, I'm writing new classes that reimplement and supply new features to the built in classes. But I have a question. I have a class called matrix, which is essentially a list with multiple columns and rows. I was wondering if when I instantiate the class, I can pass an argument to it so the __init__ function knows how big to start the Matrix. If it helps, heres the relevant code:
class Matrix(Type):
def __init__(self):
self.type = "Matrix"
self.private = False #TODO: Implement private/public type variables and accessor functions
self.value = [
[],
[],
[],
] #Defines the dimensions of the Matrix. Defaults to 3.
def expand(size):
for x in size:
self.value.append([])
def add(value, row):
self.value[row].append(value)Type is a base class I defined with just some basic functions like delete, duplicate and the such.
I want to use it in this manner:
size = 5
newInstance = Matrix(size)
And it starts with 5 columns.
Any help?
class Matrix(Type):
def __init__(self):
self.type = "Matrix"
self.private = False #TODO: Implement private/public type variables and accessor functions
self.value = [
[],
[],
[],
] #Defines the dimensions of the Matrix. Defaults to 3.
def expand(size):
for x in size:
self.value.append([])
def add(value, row):
self.value[row].append(value)Type is a base class I defined with just some basic functions like delete, duplicate and the such.
I want to use it in this manner:
size = 5
newInstance = Matrix(size)
And it starts with 5 columns.
Any help?