Apr-20-2017, 03:49 PM
1) You don't need backslashes between lines.
2) Instead of class-level init-variables, why not have all that in __init__, and have the default value be None and use the default values if nothing is passed? That way you never have to deal with shared references, since the variables simply never exist outside of an instance.
Something like:
2) Instead of class-level init-variables, why not have all that in __init__, and have the default value be None and use the default values if nothing is passed? That way you never have to deal with shared references, since the variables simply never exist outside of an instance.
Something like:
class gridSquare(object): def __init__(self, size = None, square = None): if square is None: square = [ ['0',' ','F','O','W','E','K','T','A','H'], ['1','A','G','O','X','E','L','U','B','I'], ['2','A','H','P','Y','E','M','U','C','I'], ['3','B','I','Q','Z','E','N','V','D','J'], ['4','C','I','R',' ','F','O','W','E','K'], ['5','D','J','S','A','G','O','X','E','L'], ['6','E','K','T','A','H','P','Y','E','M'], ['7','E','L','U','B','I','Q','Z','E','N'], ['8','E','M','U','C','I','R',' ','F','O'], ['9','E','N','V','D','J','S','A','G','O'] ] if size is None: size = len(square) self.square = square self.size = size grid = gridSquare() print(grid.size) # 10 print(grid.square) # ...the grid