从python类继承变量而不使用init或父类的类名



我用kivy只是为了给你一点背景…

,但我想要的是能够从另一个类调用类变量。没有init类

class FIRST-CLASS(Screen):
variables
def functions():
pass
class SECOND-CLASS(Screen,CLASSIFIERS):
*i would say FIRST-CLASS.variable but i cant...
i need a way to say parent.variable.

这是我最喜欢的方法:

使用global

您可以使用global使变量全局

class Parent():
# You need to put the global before the declaration of the variable
global var
var = 'EXAMPLE'
class Secondary():
var2 = var

最新更新