python37-能检测文件编码的模块

我先把1.txt的内容贴出来:

马纤羽     深圳    173   13711111111
乔亦菲     广州    173   15811111111
罗梦竹     北京    173   18511111111
刘诺涵     北京    175   18511111111
岳妮妮     深圳    173   18811111111
贺婉萱     深圳    173   18511111111
叶梓萱     上海    173   18011111111

安装方式 :pip3 install chardet

 1 # @Time :2019/6/9 13:34
 2 #-*- encoding:utf-8 -*-
 3 
 4 import chardet
 5 
 6 with open('1.txt',mode='rb') as f:
 7 data = f.read()
 8 # print(data)
 9 
10 print(chardet.detect(data))
11 #输出为 {'encoding': 'utf-8', 'confidence': 0.99, 'language': ''}
12 
13  print(data.decode('UTF-8'))

解释:

#{'encoding': 'utf-8', 'confidence': 0.99, 'language': ''}
'encoding': 'utf-8',这是检测出来可能的编码格式,
'confidence': 0.99,相似度0.99

转载于:https://www.cnblogs.com/Demo-simple/p/11155047.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值