i have this two methods one to read a file
def openfile(self):
dialog= QFileDialog()
dialog.setFileMode(QFileDialog.AnyFile)
dialog.setFilter(QDir.Files)
if dialog.exec_():
file_name= dialog.selectedFiles()
path = file_name[0]
if file_name[0].endswith('.py'):
with open(file_name[0],'r') as f:
data= f.read()
self.textEdit.setText(data)
f.close()
else:
pass
and the second method is save the file
def save(self):
print("saved")
text = self.textEdit.text()
file = open(filename,'w')
file.write(text)
file.close()
i want to use the variable 'filename' in the second method without losing it's value