我想打印以下版式:
extra:
identifiers:
biotools:
- http://bio.tools/abyss
我使用此代码添加节点:
yaml_file_content['extra']['identifiers'] = {}
yaml_file_content['extra']['identifiers']['biotools'] = ['- http://bio.tools/abyss']
但是,我得到了这个输出,它将工具封装在[]中:
extra:
identifiers:
biotools: ['- http://bio.tools/abyss']
我试过其他组合,但没用?在
- http://bio.tools/abyss
中的破折号表示序列元素,如果以块样式转储Python列表,则会在输出中添加该短划线。在所以与其这样做:
你应该做的是:
^{pr2}$然后使用以下命令以块样式强制输出所有组合元素:
如果需要更细粒度的控制,请创建
ruamel.yaml.comments.CommentedSeq
实例:一旦加载了YAML文件,它就不再是“YAML”;它现在是Python数据结构,
biotools
键的内容是list
:与任何其他Python列表一样,您可以
^{pr2}$append
到它:如果打印出数据结构,则会得到有效的YAML:
当然,如果出于某种原因你不喜欢这个列表表示法,你也可以得到在语法上等价的:
相关问题 更多 >
编程相关推荐