初始化方法中无法调用类变量? [关闭]

问题描述 投票:0回答:0

所以

DEFAULT_BRUSH_SIZE
被定义为类变量,如下所示:

class Grid:
    DEFAULT_BRUSH_SIZE = 2

然而,当我将

brush_size
设置为
DEFAULT_BRUSH_SIZE
时,正如橙色说明的最后一行所说,我收到错误消息“DEFAULT_BRUSH_SIZE is not defined.”

def __init__(self, draw_style, x, y) -> None:
    """
    Initialise the grid object.
    - draw_style:
        The style with which colours will be drawn.
        Should be one of DRAW_STYLE_OPTIONS
        This draw style determines the LayerStore used on each grid square.
    - x, y: The dimensions of the grid.

    Should also intialise the brush size to the DEFAULT provided as a class variable.
    """
    brush_size = DEFAULT_BRUSH_SIZE

不过,grid类中不是已经设置为2了吗?我做错了什么?

python class variables init
© www.soinside.com 2019 - 2024. All rights reserved.