How to preserve indenting in key-value when dumping yaml
问题 How to preserve indenting in key-value when dumping yaml ? I am using ruamel yaml Code: 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) Output : Pets: Cat: Tom Mouse: Jerry Dog: Scooby Bird: Tweety Expected Output: Pets: Cat: