且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

格式化 PyYAML dump() 输出

更新时间:2022-11-30 13:59:03

使用库没有简单的方法来做到这一点(yaml dumper 语法树中的节点对象是被动的,无法发出此信息),所以我结束了与

There's no easy way to do this with the library (Node objects in yaml dumper syntax tree are passive and can't emit this info), so I ended up with

stream = yaml.dump(list_of_dicts, default_flow_style = False)
file.write(stream.replace('\n- ', '\n\n- '))