我在Python中使用了以下类。这个类是我用于下棋的游戏的实用类。它包含大多数静态变量,当我尝试在静态方法中访问静态变量时,我遇到了麻烦。
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)
编译时,它会给我以下错误。
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
这可以解决哪些问题?