当前位置 : 主页 > 编程语言 > python >

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

来源:互联网 收集:自由互联 发布时间:2022-06-15
在获取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))

在获取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))

python编码问题:UnicodeDecodeError:

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:




上一篇:python json格式化打印
下一篇:没有了
网友评论