python打开文件失败,报错'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
python3.7,python3.6都存在的问题:
读取的文件编码是utf-8 第1行是空行、#开头都可能会报这个错误:
E:\count_packet>python string_count.py
'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
None
如果文件编码是ANSI就不会出现这个问题
原因:
编码的问题
解决办法:
打开文件删除第一行包含中文的行,删除空行,第1行以英文开头
python打开文件失败,报错'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence的更多相关文章
- 14 python读取文件时出现UnicodeDecodeError: 'gbk' codec can't decode byte 0xb7 in position 26: illegal multibyte sequence解决方法
>>> f = open("D:\\all.txt", "r")>>> f.read()Traceback (most re ...
- python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence
python读取文件时提示"UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal m ...
- python 读取文件时报错: UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence p ...
- python在读取文件时出现 'gbk' codec can't decode byte 0x89 in position 68: illegal multibyte sequence
python在读取文件时出现“UnicodeDecodeError:'gbk' codec can't decode byte 0x89 in position 68: illegal multiby ...
- 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence
python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...
- Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence
Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal mul ...
- python读取txt文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x8e in position 8: illegal multibyte sequence
python读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x8e in position 8: illegal multibyte ...
- python打开文件查询字符串时报UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 19: illegal multibyte sequence错误
当这样打开时报错了 lines = open(path).readlines() open(path).close() for line in lines: idx1 = line.find('检测到 ...
- python UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 87: illegal multibyte sequence异常解决
我们处理文本文件时,经常会遇到这样的报错: UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 87: illegal ...
随机推荐
- 查找idt table 所對應的page table in Linux
#include <linux/kernel.h> #include <linux/module.h> #include <linux/types.h> #incl ...
- ReplaceAll 特殊字符处理
用到Json与replaceAll Http拦截脚本中经常需要替换,replace虽然不需要处理特殊字符,但是不能匹配多个,ReplaceAll能够使用正则,不过需要处理的转移实在太多 比如,需要替换 ...
- sudo在清理内存的时候报错
运行下面语句清缓存时,报Permission denied错误:-bash: /proc/sys/vm/drop_caches: Permission denied sudo echo 1 > ...
- zabbix入门之添加主机
添加主机的方法有两种:手动添加.自动发现 前提是:在被监控主机中安装zabbix-agent.zabbix-sender组件,并配置好启动服务. 手动添加: 自动发现: 这里等待1分钟左右即可发现主机 ...
- 关于javascript提交到java后台空格去不掉ASCII为160的解决办法
今天正则表达式匹配一个字符串,怎么都不对. 用正则表达式去掉尝试str.replaceAll("\\s*",""); 在或者用replaceAll(" ...
- oracle-SQL语句执行原理和完整过程详解
SQL语句执行过程详解 一条sql,plsql的执行到底是怎样执行的呢? 一.SQL语句执行原理 第一步:客户端吧语句发个服务端执行 当我们在客户端执行select语句时,客户端会把这条SQL语句发送 ...
- Altium Designer 19使用
铺铜之后运行DRC检查弹出警告: Design contains shelved or modified (but not repoured)polygons. The result of DRC w ...
- Go 查找
sort.SearchInts(a []int, b int) 从数组a中查找b,前提是a必须有序 sort.SearchFloats(a []float64, b float64) 从数组a中查找b ...
- 商城分类导航实现 (css)
代码实例:demo.html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- shell编程程序实例
1.计算器 #!/bin/bash #test #by authors hdc 2018 function add(){ #实现加法 c=$[ $a + $b ] #相加 echo $c } func ...