[英]How to add a node with ruamel.yaml
我嘗試在該示例之后添加一個新節點,但是:
myitems = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
myitems['abc'].append('test')
給我一個錯誤:
Traceback (most recent call last):
File "item_updater.py", line 148, in <module>
myitems['wohnung'].append('test')
AttributeError: 'CommentedMap' object has no attribute 'append'
我正在使用ruamel.yaml v0.13.7
我究竟做錯了什么?
你的錯誤不是來自你指定的例子,如在inp
的例子沒有wohnung
,在你的錯誤出現。
您可能在某處忘記了-
wohnung:
a: 1
代替:
wohnung:
- a: 1
僅在后者上,您可以使用myitems['wohnung'].append('test')
。
該示例有效,但是沒有顯示您的真實YAML輸入,很難看到導致錯誤的確切原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.