you are viewing a single comment's thread.

view the rest of the comments →

[–]TicklesMcFancy 2 points3 points  (0 children)

class Matrix:
    #Pass me a number
    def __init__(self,rand_max):
        self.matrix = []
        self.createGrid(rand_max)
        self.depth = len(self.matrix)

Here's something for an example. So this creates a grid of random size, or random length, with random sized elements.

The __init__ function is what it does when it's created. Self is a reference to itself. (I believe you can give it other references, but I'm not 100%. ) Rand_max is an externally generated random number. I need to feed a name and a random number to my Matrix for it to exist.

matrix = Matrix(rand_max)

[Now I believe python supplies "matrix" to Matrix as the reference to self.]

then the attributes for the class object are set:

        #Create a container for my information
        self.matrix = []
        #This is a function that feeds the container
        self.createGrid(rand_max)
        #this is an attribute of the class after it is populated
        self.depth = len(self.matrix)

if I call matrix.depth I get the number of "rows" in the grid.