Skip to content

Instantly share code, notes, and snippets.

@puhoy
Created October 18, 2015 21:41
Show Gist options
  • Select an option

  • Save puhoy/e036af12376fb6f9884c to your computer and use it in GitHub Desktop.

Select an option

Save puhoy/e036af12376fb6f9884c to your computer and use it in GitHub Desktop.
wrapper for python dict to store as json
import json
class StoredDict(dict):
def __init__(self, filename, **kwargs):
self.filename = filename
file = open(filename, 'w+')
try:
super(StoredDict,self).__init__(json.load(file))
except ValueError:
super(StoredDict,self).__init__({})
def commit(self):
json.dump(self, open(self.filename, 'w+'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment