允许持久存储字典数据
scribble的Python项目详细描述
概述
scibble是一种将字典信息存储到持久性 国家。这样可以方便地检索和编辑数据,使其 尝试存储设置数据时的一个好选择。
注意:ScribbleDictionary中保存的数据必须是可序列化的JSON。
创建持久数据块的示例如下:
importosimportscribble# -- Instance a scribble dictionary. We can treat this exactly# -- as we treat a dictionarydata=scribble.get('foobar')# -- Set some key/value pairs in the ScribbleDictionarydata['option_a']=Truedata['option_b']=123# -- Calling .save() will trigger the dictionary# -- to store its current state to a persistent statedata.save()# -- We can see the location the data is saved to, and we can# -- see that it does indeed existprint(data.location())print(os.path.exists(data.location()))
同样,我们可以在一个全新的python实例中重新检索数据 使用以下代码:
# -- Instance a scribble dictionary with the same identifierdata=scribble.get('foobar')# -- Print the fact that we have retrieved the same # -- infromationprint(data)# {'option_a': True, 'option_b': 123}# -- We can then further edit the datadata['option_a']=False# -- Calling .save() will trigger the dictionary# -- to store its current state to a persistent statedata.save()
默认情况下,scribble会将其数据存储在以下特定平台中 位置:
窗口:appdata%/pyscribble
Linux:如果存在环境变量,则%xdggObjultGoe%/PyScript,否则%%HOM//CONFIG/PyScript B/<
OSX:_home/documents/pyscribble
但是,可以通过设置环境变量来覆盖这些路径 pyscribble_storage_dir,如果设置了此项,则该变量定义的路径 将始终用于默认行为。
相容性
这已经在ubuntu和windows上的python 2.7.13和python 3.6.6下进行了测试。
贡献
如果你想贡献思想,想法,修复或功能请联系!mike@twisted.space