我有以下文件:
stack = """
---
AWSTemplateFormatVersion: "2010-09-09"
Description: My description
Resources: {{}}
"""
我尝试在yaml文件中转储,但没有任何运气:
import yaml
import os
d='access'
stack = """
---
AWSTemplateFormatVersion: "2010-09-09"
Description: My Description
Resources: {{}}
"""
doc = yaml.load(stack)
stack_path = os.path.join('.', '{}-stack.yaml'.format(d))
with open(stack_path, 'w+b') as stack_file:
stack_file.write(yaml.dump(
doc,
default_flow_style=False,
encoding='utf-8'
))
我得到了这个结果:
yaml.scanner.ScannerError: mapping values are not allowed here
in "<unicode string>", line 3, column 33:
AWSTemplateFormatVersion: "2010-09-09"
你知道吗?
答案 0 :(得分:0)
现在删除顶部---
YAML行可以正常工作