当前位置: 代码迷 >> 综合 >> YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated
  详细解决方案

YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated

热度:7   发布时间:2024-02-07 00:03:31.0

问题描述

YAMLLoadWarning: calling yaml.load() without Loader=… is deprecated

问题分析

这是yaml加载时出错,此时要更换加载语句

解决方案

之前的代码:

__author__='yym'
import sys
import yaml
f = open('yaml_set.yaml')
content = yaml.load(f)
print(type(content))
print("修改前:", content)
content['mqtt']['num'] = 80
print("修改后:", content)

修改之后的代码:

__author__='yym'
import sys
import yaml
f = open('yaml_set.yaml')
content = yaml.load(f, Loader=yaml.FullLoader)
print(type(content))
print("修改前:", content)
content['mqtt']['num'] = 80
print("修改后:", content)

运行结果:
在这里插入图片描述
运行结果正确.

  相关解决方案