一支向阳花 2021-04-23 17:08 采纳率: 52.6%
浏览 164

linux python2.7 编写程序读取yaml文件中的内容时报错

linux python2.7 编写程序读取yaml文件中的内容时,报yaml.constructor.ConstructorError:while constructing a mapping

程序内:

with open(yaml_file, 'r') as f:
    cfg = yaml.safe_load(f)
print cfg

执行时报:yaml.constructor.ConstructorError:while constructing a mapping

  • 写回答

1条回答 默认 最新

  • Nick Peng 2021-04-23 17:33
    关注

    试试:cfg = yaml.safe_load(f.read())

    with open(yaml_file, 'r') as f:
        cfg = yaml.safe_load(f.read())
    print cfg
    评论

报告相同问题?