1

I've the following class in Python. This class is a utility class for a game of chess I'm building. It consists majority of static variables and I'm running into trouble when I try to access the static variable in a static method.

class BoardUtils:
    NUM_TILES = 64
    NUM_TILES_PER_ROW = 8

    @staticmethod
    def init_column(column):
        grid = [False] * BoardUtils.NUM_TILES
        for i in range(0 + column, BoardUtils.NUM_TILES, BoardUtils.NUM_TILES_PER_ROW):
            grid[i] = True
        return grid

    @staticmethod
    def init_row(row):
        grid = [False] * BoardUtils.NUM_TILES
        for i in range(BoardUtils.NUM_TILES_PER_ROW * row,
                   BoardUtils.NUM_TILES_PER_ROW * (row + 1)):
            grid[i] = True
        return grid

    FIRST_COLUMN = init_column.__func__(0)
    SECOND_COLUMN = init_column.__func__(1)
    SEVENTH_COLUMN = init_column.__func__(6)
    EIGHTH_COLUMN = init_column.__func__(7)
    SECOND_ROW = init_row.__func__(1)
    SEVENTH_ROW = init_row.__func__(6)

while compiling, it gives me following error.

Traceback (most recent call last):
  File "alice5500.py", line 27, in <module>
    class BoardUtils:
  File "alice5500.py", line 46, in BoardUtils
    FIRST_COLUMN = init_column.__func__(0)
  File "alice5500.py", line 33, in init_column
    grid = [False] * BoardUtils.NUM_TILES
NameError: global name 'BoardUtils' is not defined

What can be a workaround in this?

Dishant Kapadiya
  • 523
  • 4
  • 10
  • Possible duplicate of [calling class/static method from class variable in python](http://stackoverflow.com/questions/5004837/calling-class-static-method-from-class-variable-in-python) – Meyer Nov 24 '16 at 23:35

0 Answers0