human
I am working on the file "DataPersistence/Pickle.ipynb".
The first task is:
Problem with Reconstructing Objects
Can you write Python code for it?
assistant
#Here is the Python code you requested.

import pickle
import sys

class SimpleObject:

    def __init__(self, name):
        self.name = name
        l = list(name)
        l.reverse()
        self.name_backwards = ''.join(l)
data = []
data.append(SimpleObject('pickle'))
data.append(SimpleObject('preserve'))
data.append(SimpleObject('last'))

filename ='test.dat'

with open(filename, 'wb') as out_s:
    for o in data:
        print('WRITING: {} ({})'.format(
            o.name, o.name_backwards))
        pickle.dump(o, out_s)

with open(filename, 'rb') as in_s:
    while True:
        try:
            o = pickle.load(in_s)
        except EOFError:
            break
        else:
            print('READ: {} ({})'.format(
                o.name, o.name_backwards))