Saving an Object (Data persistence)

You could use the pickle module in the standard library. Here’s an elementary application of it to your example: import pickle class Company(object): def __init__(self, name, value): self.name = name self.value = value with open(‘company_data.pkl’, ‘wb’) as outp: company1 = Company(‘banana’, 40) pickle.dump(company1, outp, pickle.HIGHEST_PROTOCOL) company2 = Company(‘spam’, 42) pickle.dump(company2, outp, pickle.HIGHEST_PROTOCOL) del company1 del … Read more