spock
6/10/2017 - 8:20 PM

Example for using the shelve module for data persistence.

Example for using the shelve module for data persistence.

import shelve

d = shelve.open(DATA_FILE, writeback=True)

# creating key if it does not exist 
# is there a function for this already?
try:
  d["records"]
except KeyError:
  d["records"] = []  # initialize list
try:
  d["model"]
except KeyError:
  d["model"] = []  # initialize list

d.close()