import pickle import os def write_to_file(data, filename): with open(filename, 'wb') as file: pickle.dump(data, file) def read_from_file(filename): if not os.path.exists(filename): open(filename, 'w').close() # Create a blank file if it doesn't exist return [] with open(filename, 'rb') as file: try: data = pickle.load(file) except: print("An exception occurred") return [] return data