Python‎ > ‎

Use Python Shelve to store a Variable to disk

posted Feb 21, 2014, 11:14 PM by Chris G   [ updated Sep 4, 2014, 11:49 PM ]
Python includes the wonderful "shelve" feature, which allows the developer to store the content of variable to disk so that they are preserved between executions of the program.

import shelve

dbase = shelve.open("mydbase")

try:
    sunSetTime = dbase['sunSetTime']
except:
    sunSetTime = datetime.datetime(now.year, now.month, now.day, 18, 00, 15)
finally:
    dbase.close()

Comments