我想从一个类方法中调用一个变量到同一个类中的不同方法: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
提交
取消
