python - 需要帮助使用 python 创建复杂的 yaml
问题描述
我有以下代码
name = "testyaml"
version = "2.5"
os = "Linux"
sources = [
{
'source': 'news',
'target': 'industry'
},
{
'source': 'testing',
'target': 'computer'
}
]
我想用python3制作这个yaml
services:
name: name,
version: version,
operating_system: os,
sources:
-
source: news
target: industry
-
source: testing
target: computer
我需要特别在 Sources 部分的帮助,我可以在那里添加我的字典列表
解决方案
import yaml
name = "testyaml"
version = "2.5"
os = "Linux"
sources = [
{"source": "news", "target": "industry"},
{"source": "testing", "target": "computer"},
]
yaml.dump(
{"services": {"name": name, "version": version, "os": os, "sources": sources}}
)
推荐阅读
- xamarin.forms - 如何在自定义 HttpMessageHandler 中设置属性?
- graphql-spqr - 有没有办法在@GraphqQuery 方法中读取请求标头
- gradle - 支持的最低 Gradle 版本为 6.1.1。当前版本是 5.6.4
- python - 导入 SMOTE 时出现不平衡学习模块 base.py 文件语法错误
- r - devtools::check() 注意到 .lintr 作为隐藏文件和目录
- flutter - 如何在边框中左右对齐
- javascript - 在 http 请求中使用 2 .then 的目的是什么?
- xamarin.forms - MSAL 提示(Microsoft 身份验证库)因 Intune 公司门户应用程序而失败
- javascript - 将焦点放在输入上并更改 li 背景颜色
- c++ - 关于两个类构造函数的C++问题