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?

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.