Python Storing Data


I have a list in my program. I have a function to append to the list, unfortunately when you close the program the thing you added goes away and the list goes back to the beginning. Is there any way that I can store the data so the user can re-open the program and the list is at its full.

Best Solution

You may try pickle module to store the memory data into disk,Here is an example:

store data:

import pickle
dataset = ['hello','test']
outputFile = ''
fw = open(outputFile, 'wb')
pickle.dump(dataset, fw)

load data:

import pickle
inputFile = ''
fd = open(inputFile, 'rb')
dataset = pickle.load(fd)
print dataset