python2判断编码格式
def getCoding(strInput):
'''
获取编码格式
'''
if isinstance(strInput, unicode):
return "unicode"
try:
strInput.decode("utf8")
return 'utf8'
except:
pass
try:
strInput.decode("gbk")
return 'gbk'
except:
pass def tran2UTF8(strInput):
'''
转化为utf8格式
'''
strCodingFmt = getCoding(strInput)
if strCodingFmt == "utf8":
return strInput
elif strCodingFmt == "unicode":
return strInput.encode("utf8")
elif strCodingFmt == "gbk":
return strInput.decode("gbk").encode("utf8") def tran2GBK(strInput):
'''
转化为gbk格式
'''
strCodingFmt = getCoding(strInput)
if strCodingFmt == "gbk":
return strInput
elif strCodingFmt == "unicode":
return strInput.encode("gbk")
elif strCodingFmt == "utf8":
return strInput.decode("utf8").encode("gbk")
python2判断编码格式的更多相关文章
- java判断编码格式
package com.sssjd.storm; import java.io.UnsupportedEncodingException; /** * Created by jorda on 2017 ...
- chardet库:识别文件的编码格式
chardet库文档 http://chardet.readthedocs.io/en/latest/usage.html 小文件的编码判断 detect函数只需要一个 非unicode字符串参数,返 ...
- python全栈开发中级班全程笔记(第二模块)第一部分:文件处理
第二模块 第一部分:文件处理与函数 #插曲之人丑就要多读书:读书能够提高个人素质与内涵,提升个人修养与能力,以及层次的提升. 推荐书籍:追风筝的人.白鹿原 电影:阿甘正传.辛德勒的名单 第一节:三 ...
- python基础知识-01-编码输入输出变量
python其他知识目录 名词解释: 编辑器 ide 程序员 操作系统 ASCAII码 unicode utf-8 浅谈CPU.内存.硬盘之间的关系 操作系统及Python解释器工作原理讲解 关于编译 ...
- Python分布式爬虫打造搜索引擎完整版-基于Scrapy、Redis、elasticsearch和django打造一个完整的搜索引擎网站
Python分布式爬虫打造搜索引擎 基于Scrapy.Redis.elasticsearch和django打造一个完整的搜索引擎网站 https://github.com/mtianyan/Artic ...
- Python简单爬虫入门一
为大家介绍一个简单的爬虫工具BeautifulSoup BeautifulSoup拥有强大的解析网页及查找元素的功能本次测试环境为python3.4(由于python2.7编码格式问题) 此工具在搜索 ...
- 基于Winform的.cs文件命名空间排序及注释批量处理工具
公司里每个程序员在命名空间的排序和注释上都有很多的不同. 杂乱的命名空间: using System; using System.Collections.Generic; using Autodesk ...
- GJM : Python简单爬虫入门 (一) [转载]
版权声明:本文原创发表于 [请点击连接前往] ,未经作者同意必须保留此段声明!如有侵权请联系我删帖处理! 为大家介绍一个简单的爬虫工具BeautifulSoup BeautifulSoup拥有强大的解 ...
- chardet 模块
#coding:utf-8 #指定本文件编码为utf-8 #python 27 #xiaodeng #chardet模块 #chardet模块下载地址: #1)http://pan.baidu.com ...
随机推荐
- git填坑笔记
Counting objects: 3, done.Writing objects: 100% (3/3), 203 bytes | 0 bytes/s, done.Total 3 (delta 0) ...
- 步步为营-30-AES加密与解密
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- AOJ 0005 GCD and LCM
题意:求两数最大公约数和最小公倍数. 类型:辗转相除法 算法:gcd(a,b)=gcd(b,a%b),lcm(a,b)=a*b/gcd(a,b). #include <cstdio> #i ...
- java:大小写字母转换
public class Solution { public static void main(String args[]) { testSolutions.lowercaseToUppercase( ...
- 020 SpringMVC返回Json
一:处理Json 1.添加jar包 添加json需要的包 2.后端返回json对用的对象或者集合 使用ResponseBody标签 package com.spring.it.json; import ...
- 019 mapreduce的核心--shuffle理解,以及在shuffle中的优化
关于shuffle的过程图. 一:概述shuffle Shuffle是mapreduce的核心,链接map与reduce的中间过程. Mapp负责过滤分发,而reduce则是归并整理,从mapp输出到 ...
- Java—集合框架详解
一.描述Java集合框架 集合,在Java语言中,将一系类的对象看成一个整体. 首先查看jdk中的Collection类的源码后会发现Collection是一个接口类,其继承了java迭代接口Iter ...
- 8,EasyNetQ-多态发布和订阅
您可以订阅一个接口,然后发布该接口的实现. 我们来看一个例子. 我有一个接口IAnimal和两个实现猫和狗: public interface IAnimal { string Name { get; ...
- 解决binwalk运行提示缺少LZMA模块
解决binwalk运行提示缺少LZMA模块 部分用户在使用binwalk提取固件内容,可能会遇到缺少LZMA模块的提示.提示内容为WARNING:The Python LZMA module co ...
- vue中的dom基本渲染
一.输出动态标签请只对可信内容使用HTML插值,绝不要对用户提供的内容使用插值,容易导致xss攻击. <div id="J_app"> <div v-html=& ...