python编码问题:UnicodeDecodeError: 'gbk' codec can't decode

2021-04-08 04:25

阅读:518

标签:err   aml   erro   print   inf   数据   打开   编码问题   illegal   

在获取yaml文件数据时,提示:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x80 in position 2: illegal multibyte sequence

import yaml
def test_yaml():
    with open(‘../test_python/yaml_data.yaml‘) as f:
        print(yaml.safe_load(f))

技术图片

import yaml
def test_yaml():
    # 声明编码:encoding=‘utf-8‘
    with open(‘../test_python/yaml_data.yaml‘,encoding=‘utf-8‘) as f:
        print("使用:encoding=‘utf-8‘")
        print(yaml.safe_load(f))

    # 以二进制格式打开一个文件用于只读  
    with open(‘../test_python/yaml_data.yaml‘,‘rb‘) as f:
        print("使用:‘rb‘")
        print(yaml.load(f))

技术图片

python编码问题:UnicodeDecodeError: 'gbk' codec can't decode

标签:err   aml   erro   print   inf   数据   打开   编码问题   illegal   

原文地址:https://www.cnblogs.com/Uni-Hoang/p/13379657.html


评论


亲,登录后才可以留言!