I use pickle in order to save a list of objects. After saving the list with pickle and loading this very same list again I compare the newly loaded list with the original list. Strangely those two objects differ. Why is this the case? Shouldn't it be the same?
I already tried to use only instance attributes that are defined in the init-function and no class attributes but the error remains.
import pickle as p
class Person(object):
def __init__(self, name=None, job=None, quote=None):
self.name = name
self.job = job
self.quote = quote
personList = [Person("Payne N. Diaz", "coach", "Without exception, there is no rule!"),
Person("Mia Serts", "bicyclist", "If the world didn't suck, we'd all fall off!"),
Person("Don B. Sanosi", "teacher", "Work real hard while you wait and good things will come to you!")]
with open('test_list.p', 'wb') as handle:
p.dump(personList, handle, protocol=p.HIGHEST_PROTOCOL)
with open('test_list.p', 'rb') as handle:
personList2 = p.load(handle)
print(personList == personList2)
I expect that True will be printed out but the result printed is False.