我從YAML數據製作一個文檔生成器,它將指定每個項目從哪個YAML文件生成。做這個的最好方式是什麼?因此,如果YAML文件是這樣的:解析YAML,用行號返回
- key1: item 1
key2: item 2
- key1: another item 1
key2: another item 2
我想是這樣的:
[
{'__line__': 1, 'key1': 'item 1', 'key2': 'item 2'},
{'__line__': 3, 'key1': 'another item 1', 'key2': 'another item 2'},
]
我目前使用PyYAML,但是任何其他庫是確定的,如果我可以從Python中使用它。
謝謝 - 這個工作完美,並且在錯誤報告方面非常有用。 –