• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python使用chardet判断字符编码

Python使用chardet判断字符编码

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python chardet,python chardet下载,python chardet模块,chardet,chardet下载等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python使用chardet判断字符编码的方法。分享给大家供大家参考。具体分析如下:

Python中chardet 用来实现字符串/文件编码检测模板

1、chardet下载与安装

下载地址:http://pypi.python.org/pypi/chardet

下载chardet后,解压chardet压缩包,直接将chardet文件夹放在应用程序目录下,就可以使用import chardet开始使用chardet了,也可以将chardet拷贝到Python系统目录下,这样你所有的python程序只要用import chardet就可以了。

python setup.py install
</div>

2、实例

使用中,chardet.detect()返回字典,其中confidence是检测精确度,encoding是编码形式

(1)网页编码判断:

>>> import urllib
>>> rawdata = urllib.urlopen('http://www.google.cn/').read()
>>> import chardet
>>> chardet.detect(rawdata)
{'confidence': 0.98999999999999999, 'encoding': 'GB2312'}
</div>

(2)文件编码判断

import chardet
tt=open('c:\\111.txt','rb')
ff=tt.readline()
#这里试着换成read(5)也可以,但是换成readlines()后报错
enc=chardet.detect(ff)
print enc['encoding']
tt.close()
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • python判断字符串编码的简单实现方法(使用chardet)
  • Python使用chardet判断字符编码
  • python使用chardet判断字符串编码的方法
  • 使用python的chardet库获得文件编码并修改编码

相关文章

  • python之文件的读写和文件目录以及文件夹的操作实现代码
  • python计算时间差的方法
  • python计算方程式根的方法
  • python引用DLL文件的方法
  • python 遍历字符串(含汉字)实例详解
  • Python实现把xml或xsl转换为html格式
  • 整理Python最基本的操作字典的方法
  • 在Python中操作日期和时间之gmtime()方法的使用
  • Python程序员开发中常犯的10个错误
  • 使用Python脚本来控制Windows Azure的简单教程

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python map和reduce函数用法示例
    • python实现根据月份和日期得到星座的方法
    • Python的Flask框架中的Jinja2模板引擎学习教程
    • Python动态加载模块的3种方法
    • Python中实现的RC4算法
    • Python列表(list)、字典(dict)、字符串(string)基本操作小结
    • Python的string模块中的Template类字符串模板用法
    • 基于python实现微信模板消息
    • Go语言基于Socket编写服务器端与客户端通信的实例
    • python简单获取本机计算机名和IP地址的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有