如何更改引用不同类的不同python文件中变量的值?

如何更改引用不同类的不同python文件中变量的值?,python,python-3.x,class,import,scope,Python,Python 3.x,Class,Import,Scope,我有一个主python文件和一个不同python文件中的类。我试图从类中更改python文件中的一个变量。但是,我不知道如何在\uuuu init\uuuu函数之外执行此操作 班级: class Matrices: currentMenuItem = 0 dataForMatrix = {} def __init__(self, memory, matricesFrame, tempBoolsControl, otherControls): self.m

我有一个主python文件和一个不同python文件中的类。我试图从类中更改python文件中的一个变量。但是,我不知道如何在
\uuuu init\uuuu
函数之外执行此操作

班级:

class Matrices:
    currentMenuItem = 0
    dataForMatrix = {}

    def __init__(self, memory, matricesFrame, tempBoolsControl, otherControls):
        self.memory = memory
        self.matricesFrame = matricesFrame
        self.tempBoolsControl = tempBoolsControl
        self.otherControls = otherControls

    def createNewMatrix(self):
        self.otherControls["right"] = False
主文件:

from Matrices import Matrices

otherControls = {"right": True, "left": True}

Matrices(memory, matricesFrame, tempBoolsControl, otherControls).createNewMatrix()

这意味着更改主文件中的
otherControls
变量,但它仅在本地更改它。我无法访问
\uu init\uu
函数之外的原始
其他控件
变量。有人能帮忙吗?

如果您将矩阵对象保存到变量,例如

mat=矩阵(内存、矩阵帧、tempBoolsControl、其他控件)。createNewMatrix()

您可以像这样访问
otherControls
属性:

mat.otherControls = {'right':True, 'left':False}
# or if you want only one of the keys
mat.otherControls['right'] = False

局部变量
其他控件
!=类属性
self.othercontrols