Jan-05-2018, 09:27 PM
Here is a basic example of writing such a pickle file. Use it once with
WRITE = True
to create the file foo.pkl
, then use it as many times as you need with WRITE = False
to use the data.from collections import namedtuple import pickle Record = namedtuple('Record', "id foo bar baz") WRITE = False if WRITE: L = [Record(i, "a"*100, "b" * 50, "c" * 50) for i in range(30000)] print('Writing') with open('foo.pkl', 'wb') as ofh: pickle.dump(L, ofh) else: print('Reading') with open('foo.pkl', 'rb') as ifh: L = pickle.load(ifh) print(len(L)) print(L[17865])