我想從一個類方法中調用一個變量到同一個類中的不同方法:class A(): @classmethod def b(cls): cls.g = 5 def c(self): if self.g < 1: print("TestA") else: print("TestB")做的時候:x = A()x.c()我得到:AttributeError: 'A' object has no attribute 'g'我已經閱讀并搜索了一個類似的案例,但沒有找到。大多數處理從 init 方法調用變量,這在這里不適用。
添加回答
舉報
0/150
提交
取消