在Python中的Yaml转储

时间:2017-10-10 08:05:05

标签: python yaml pyyaml

我有以下文件:

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"
你知道吗?

1 个答案:

答案 0 :(得分:0)

现在删除顶部--- YAML行可以正常工作