繁体   English   中英

通过Python读取txt文件时出现编解码器问题

[英]Codec issue while reading txt file via Python

在尝试使用简单的open ()方法使用Python 3.6打开.txt文件(其中仅包含纯文本open ()遇到问题:

with open('3003.txt', 'r') as myfile:
    data=myfile.read()

它给出了这样的错误跟踪:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 182: invalid continuation byte

我使用了几种谷歌搜索方法,但是它们不能解决交易。 应该怎么做才能解决这个问题?

您可以使用Python 3 open()样式文件处理程序来流字节字符串:

open('3003.txt', 'rb') as myfile:
    data=myfile.read()

注意“ b”表示二进制模式

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM