def save_to_disk(self):
"""
Commit the data from memory to disk.
Returns True or False depending on success/failure.
"""
# Create file if it doesn't exist.
if not os.path.exists(self.file_path):
open(self.file_path, "w").close()
# Write new data to specified file.
if os.access(self.file_path, os.W_OK):
f = open(self.file_path, "w+")
f.write(json.dumps(self.data, sort_keys=True, indent=4))
f.close()
return True
else:
return False
评论列表
文章目录