I have a python script in which I have numerous PyQt5 widgets. The script basically calculates some data which is stored mostly in lists. This data is then used with PyQt5 widgets and matplotlib tools to present the results.
What I want to do is a very common question which I am aware is asked many times. However, I could not come up with a post which involves PyQt5 and matplotlib. So I want to store all the data that is calculated and all the PyQt5 widgets and matplotlib plots to load it later.
The most practical method I saw in my search is pickle. However, with pickle I have to 'dump' the results as a list containing floats and then remember the order in which they were dumped to reassign them when I load the pickled file. This is a tedious process and also there is the problem of losing float precision using pickle.
My question is:
Is there any alternative method you would recommend other than pickle to save a workspace which includes data consisting of floats, lists of floats, PyQt5 widgets and matplotlib plots and tables? I saw QSettings but as far as I understood it deals with only appearance of widgets.
If pickle is the most practical way, is there a way I can create a dictionary with the name of the variable as the key and its value as the value of the dictionary, so I do not have to reassign pickle-loaded file's indexes back to my variables one by one?
A very basic script to help explain what I want to do:
def input():
x = []
y = []
for i in range(0,10):
x.append(i*2)
y.append(i*4)
func(x, y)
def func(x, y):
'''
matplotlib plot initiation code
FigureCanvas initiation code
'''
plot.axes.plot(x, y)
plotcanvas.draw()
I want to save x, y, plot and plotcanvas to be able to load it later in a practical way.