Answer the question
In order to leave comments, you need to log in
PyQt4 | What is the best way to read a list from a file?
# Python 3. PyQt4
I want to load the initial data from the file for the test calculation. In the file, the data is written as a list, i.e.: [20, 8, 4]
There is a code that reads this data from the file and inserts it into the fields:
def on_open_isd (self):
options = QtGui.QFileDialog.Options()
self.fileName = QtGui.QFileDialog.getOpenFileName(self, "Открыть как", "ИД. Расчёт объёма.txt",
"Text Files (*.txt)", options=options)
if self.fileName:
self.readFile = open(self.fileName, 'r', encoding='utf-8')
open_isd = self.readFile.read()
self.readFile.close()
open_isd = open_isd[1:-1].replace(' ','')
open_isd = open_isd.split(',')
self.pole_a.setText(str(open_isd[0]))
self.pole_b.setText(str(open_isd[1]))
self.pole_h.setText(str(open_isd[2]))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question