我试图在dataclass
(y_set_max
和y_set_min
) 中声明两个变量。下面是我的代码:
from dataclasses import dataclass
@dataclass
class Ymax_ymin: #has to be object inside the brackets
y_default_max: int #500
y_default_min: int #0
current: int
recommended: int
def __post_init__(self):
self.y_set_max = max(y_default_max,current,recommended)
self.y_set_min = min(y_default_min,current,recommended)
current = 800
recommended = 650
set_axis = Ymax_ymin(500,0,current,recommended)
print(set_axis.y_set_max)
print(set_axis.y_set_min)
这是抛出错误: NameError: name y_default_max
is not defined
如何修改我的dataclass
代码以便返回两个打印语句?