I am trying to pickle the namedtuple
like this:
def f():
TemplateData = namedtuple('TemplateData', ['field1', 'field2'])
f1 = np.random.randn(50,50)
f2 = np.random.randn(50,50)
td = TemplateData(f1, f2)
return td
data = f()
with open("aaaa.pkl", "wb") as fl:
pkl.dump(data, fl)
but this crashes due to error:
PicklingError: Can't pickle <class '__main__.TemplateData'>: it's not the same object as __main__.TemplateData
What's wrong?
If pickle
is not the best way to store named tuple - what is the most efficient way?