def save_table(table_loc, table):
"""
Saves a table of type ``table_type`` to a YAML file ``table_loc``
"""
table_list = [obj.to_dict_sparse() for obj_id, obj in table.items()]
table_obj = {
'db_version': DB_VERSION,
'data': table_list
}
if os.path.exists(table_loc):
# Cache a backup of this
shutil.copy2(table_loc, _get_bak_loc(table_loc))
with open(table_loc, 'w') as yf:
yaml.dump(table_obj, stream=yf, default_flow_style=False)
评论列表
文章目录