转储 yaml 时如何保留键值缩进?我正在使用 ruamel yaml
代码:
in_str='''Pets:
Cat:
Tom
Mouse:
Jerry
Dog:
Scooby
'''
import ruamel.yaml, sys
results = ruamel.yaml.load(in_str, ruamel.yaml.RoundTripLoader, preserve_quotes=True)
results['Pets']['Bird']='Tweety'
ruamel.yaml.dump(results, sys.stdout, ruamel.yaml.RoundTripDumper, default_flow_style=True,indent=2, block_seq_indent=2)
输出 :
Pets:
Cat: Tom
Mouse: Jerry
Dog: Scooby
Bird: Tweety
预期输出:
Pets:
Cat:
Tom
Mouse:
Jerry
Dog:
Scooby
Bird:
Tweety