I have a question about data storage. I have a program that is creating a list of objects. What is the best way to store these on file so that the program can reload them later? I've tried to use Pickle, but I think I might be heading down the wrong alley and I keep getting this error when I try to read back the data:
Traceback (most recent call last):
File "test.py", line 110, in <module>
knowledge = pickle.load(open("data.txt"))
File "/sw/lib/python3.1/pickle.py", line 1356, in load
encoding=encoding, errors=errors).load()
File "/sw/lib/python3.1/codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0: invalid start byte
Edited to add: here's a bit of the code I'm trying:
FILE = open("data.txt", "rb")
knowledge = pickle.load(open("data.txt"))
FILE = open("data.txt", 'wb')
pickle.dump(knowledge, FILE)