如何在没有自引用的情况下获取类中的变量



我有一个类:

class B(A):
def __init__(self, param):
self.param = param

param_outside_function = param #<-------------- how to get the variable param inside the class and outside the class function without using `self`?

使用global param而不是"自我;并在类之外声明

我不确定你需要什么,但这可能会有所帮助:创建一个返回此变量的方法,但您仍将使用self.method:

class B(A):
def __init__(self, param):
self.param = param

def getParam(self):
return self.param

最新更新