用于存储在文本文件中的json数据的json存储管理器
json-storage-manager的Python项目详细描述
json存储管理器
json-storage-manager
是一个python包,它简单地使用demo store api存储的产品和订单数据管理json文件。
安装
pip install json-storage-manager
原子
使用量
atomic
基本上用作编写json文件的自定义上下文管理器,而不必停止原始文件的运行。
它只需将json文件加载到内存中,并使用tempfile
python包打开一个临时文件,最后,一旦操作完成,它将执行os.replace()
来替换原始文件(这是linux系统上的原子操作)。
fromjson_storage_managerimportatomicwithatomic.atomic_write(str(json_file))astemp_file:withopen(str(json_file))asproducts_file:# get the JSON data into memoryproducts_data=json.load(products_file)# now process the JSON dataproducts_data.append({'uuid':"2299d69e-deba-11e8-bded-680715cce955",'special_price':111.0,'name':"Test Product"})json.dump(products_data,temp_file)