if len(sys.argv) != 3:
print "usage: python render_template.py [yaml_file] [jinja_template_file]"
sys.exit(1)
with open(sys.argv[1], "r") as stream:
config = yaml.safe_load(stream)
with open(sys.argv[2], "r") as stream:
template_text = stream.read()
template = Template(template_text)
print template.render(config)
test.yaml:
^{pr2}$
在sample.json.templete在[{
"test1":
{
"objectName": "{{Application.Hosts}}",
}
}]
我跑的时候python ./render.py ./test.yaml ./sample.json.templete > sample.json
我明白了[{
"test1":
{
"objectName": ['a' , 'b'],
}
}]
但是由于我要生成一个json文件,所以我需要["a", "b"]
也就是说,我要用双引号把这个名单写上。我怎样才能最好地实现它?如何将单引号中的字符串列表转换为双引号中的字符串列表?在