How to pickle a namedtuple instance correctly
Create the named tuple outside of the function: from collections import namedtuple import pickle P = namedtuple(“P”, “one two three four”) def pickle_test(): my_list = [] abe = P(“abraham”, “lincoln”, “vampire”, “hunter”) my_list.append(abe) with open(‘abe.pickle’, ‘wb’) as f: pickle.dump(abe, f) pickle_test() Now pickle can find it; it is a module global now. When unpickling, all … Read more