python-yaml.dump schlechte Einrückung

Ich bin mit dem ausführen des folgenden python-code:

import yaml


foo = {
    'name': 'foo',
    'my_list': [{'foo': 'test', 'bar': 'test2'}, {'foo': 'test3', 'bar': 'test4'}],
    'hello': 'world'
}

print(yaml.dump(foo, default_flow_style=False))

aber ist Druck:

hello: world
my_list:
- bar: test2
  foo: test
- bar: test4
  foo: test3
name: foo

statt:

hello: world
my_list:
  - bar: test2
    foo: test
  - bar: test4
    foo: test3
name: foo

Wie kann ich das Einrücken der my_list Elemente auf diese Weise?

  • Beide Versionen sind korrekt, also im schlimmsten Fall ist dies ein ästhetisches Anliegen.
InformationsquelleAutor fj123x | 2014-08-03
Schreibe einen Kommentar