美文网首页
python读取yaml文件yaml.composer.Comp

python读取yaml文件yaml.composer.Comp

作者: _karen | 来源:发表于2020-09-29 15:25 被阅读0次

第一个问题

报错

yaml.composer.ComposerError: expected a single document in the stream

原因:yaml文档中用---分割,有多个文档,而读取的时候用了yaml.load()方法
【解决方案一】
将yaml.load()方法改成yaml.loadall()

datas = yaml.load_all(file_data, Loader=yaml.FullLoader)
print(datas)
print(type(datas))

注意:输出最后生成的datas和data的类型是:
<generator object load_all at 0x0000017829B079C8>
<class 'generator'>

【解决方案二】
将文档中的---去掉,变成document1

datas = yaml.load_all(file_data, Loader=yaml.FullLoader)
print(datas)
print(type(datas))

最后输出的:datas是字典 dict

第二个问题:
报错

YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe

【解决方案一】
将yaml.load()方法改成yaml.loadall()
【解决方案二】
load后面加上参数Loader=yaml.FullLoader
datas = yaml.load(file_data, Loader=yaml.FullLoader)

相关文章

  • python读取yaml文件yaml.composer.Comp

    第一个问题 报错 原因:yaml文档中用---分割,有多个文档,而读取的时候用了yaml.load()方法【解决方...

  • yaml 文件管理

    yaml文件管理,包括读取yaml文件内容,写入yaml文件,清空yaml文件。

  • python读取文件 - yaml

    yaml,Yet Another Markup Language,另一种标记语言。专门用来写配置文件的语言,简洁、...

  • 7.Python读取yaml文件封装

    yaml读取文件封装 yaml文件读取封装,需要传入文件参数来获取文件数据 yaml基础知识 yaml支持的数据类...

  • Python做接口测试读取yaml文件时,no变成了False,

    我们先来写一个测试用的yaml文件 然后再来写一段python来读取这个yaml文件的内容 调用read_yaml...

  • python群发邮件

    python发送邮件 发送一个普通文本邮件 参数化--读取yaml配置文件 yaml配置文件 打包发送带附件的邮件

  • 通过snakeyaml解析yaml文件

    scala 读取yaml 配置文件 配置maven文件pom.xml 创建yaml 文件config.yaml ...

  • yaml实现参数化

    从yaml文件中读取数据 1、准备名字为「keys_data」的yaml数据: 2、读取yaml文件中的数据 ya...

  • python配置

    python读取配置文件方式(ini、yaml、xml) - 云+社区 - 腾讯云 (tencent.com)[h...

  • Python读取yaml文件内容

    yaml文件的应用已经越来越多了,大小写敏感、用缩进表示层级关系、注释使用“#”。 本文是根据yml文件中的浏览器...

网友评论

      本文标题:python读取yaml文件yaml.composer.Comp

      本文链接:https://www.haomeiwen.com/subject/oleeuktx.html