python 2 encode and decode
https://docs.python.org/2/howto/unicode.html
a Unicode string is a sequence of code points, which are numbers from 0 to 0x10ffff. This sequence needs to be represented as a set of bytes (meaning, values from 0–255) in memory. The rules for translating a Unicode string into a sequence of bytes are called an encoding.
一个Unicode字符串是一个序列的编码点,是从0至0x10ffff的数值。这个序列需要在内存中表示为一组字节(意味着从0到255的值)。将一个Unicode字符串翻译成一个字节序列被称为编码。
UTF-8 is probably the most commonly supported encoding. UTF stands for “Unicode Transformation Format”, and the ‘8’ means that 8-bit numbers are used in the encoding
utf-8 是最普遍支持的编码。utf 表示“统一编码转换格式”, 8 表示8位编码统一编码转换格式
Python’s 8-bit strings have a .decode([encoding], [errors]) method that interprets the string using the given encoding
Python的8位字符串有一个解码([编码],[错误])方法,它使用给定的编码来解释字符串
The unicode()constructor has the signature unicode(string[, encoding, errors]). All of its arguments should be 8-bit strings. The first argument is converted to Unicode using the specified encoding; if you leave off the encoding argument, the ASCII encoding is used for the conversion, so characters greater than 127 will be treated as errors
unicode()构造体有个标志函数unicode(string[, encoding, errors]).所有参数都应是8比特字符串。使用指定的编码将第一个参数转换为Unicode;如果去掉编码参数,则使用ASCII编码进行转换,因此大于127的字符将被视为错误。
python 2 encode and decode的更多相关文章
- Python 关于 encode与decode 中文乱码问题
字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(en ...
- python 的 encode 、decode、字节串、字符串
一.摆个图 DJ DJ DJ Decode. J 解码 首先得知道字符串有哪些编码格式,至于为什么会有这么多的编码格式,以后再了解更新. 1.ASCII 占1个字节,只支持英文 2.GB231 ...
- python编码encode和decode
计算机里面,编码方法有很多种,英文的一般用ascii,而中文有unicode,utf-8,gbk,utf-16等等. unicode是 utf-8,gbk,utf-16这些的父编码,这些子编码都能转换 ...
- python之encode和decode编码
u = '中文' str3 = u.encode('utf-8') # 以utf-8编码对u进行编码,获得bytes类型对象 print(str3) u2 = str3.decode('utf-8') ...
- 【python】python新手必碰到的问题---encode与decode,中文乱码[转]
转自:http://blog.csdn.net/a921800467b/article/details/8579510 为什么会报错“UnicodeEncodeError:'ascii' codec ...
- 【python】浅谈encode和decode
对于encode和decode,笔者也是根据自己的理解,有不对的地方还请多多指点. 编码的理解: 1.编码:utf-8,utf-16,gbk,gb2312,gb18030等,编码为了便于理解,可以把它 ...
- python encode和decode函数说明【转载】
python encode和decode函数说明 字符串编码常用类型:utf-8,gb2312,cp936,gbk等. python中,我们使用decode()和encode()来进行解码和编码 在p ...
- 字符编码和python使用encode,decode转换utf-8, gbk, gb2312
ASCII码 标准ASCII码使用7位二进制数表示大写或小写字母,数字0到9标点符号以及在美式英语中使用的特殊控制字符. 在标准ASCII码中,最高位(b7)用作奇偶校验位,所谓奇偶校验,是指在代码传 ...
- python的str,unicode对象的encode和decode方法
python的str,unicode对象的encode和decode方法 python中的str对象其实就是"8-bit string" ,字节字符串,本质上类似java中的byt ...
随机推荐
- center os 安装mysql5.6
软件 MySQL-server-5.6.13-1.el6.x86_64.rpm MySQL-client-5.6.13-1.el6.x86_64.rpm 安装命令 rpm -ivh MySQL-ser ...
- 一种struts标签取不到值的情况
编写一个网页,使用<s:date >标签将日期格式化,使用了多组数据一直没有问题,突然在一组数据上死活出现不了数据了.程序如下 <s:iterator value="art ...
- undefined reference to 'pthread_create'问题解决(转载)
转自:http://blog.csdn.net/llqkk/article/details/2854558 由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个例子 ...
- bzoj 2809: [Apio2012]dispatching【dfs序+主席树】
可并堆就可以,但是想复健一下主席树. 考虑枚举管理者,然后选忍者的时候在子树中贪心的从小到大选.做成dfs序就是选区间内和小于等于k的最多点.可以用主席树,查询的时候在主席树上二分即可 这里注意,为了 ...
- 关于python安装lxml插件的问题
文章只是介绍自己安装时从安装不上到安装后报错,再到安装成功的心路历程,并不代表广大欧皇也会会出现同类型的问题,也不是总结和汇总各种出问题的原因. 直接进入正题,首先我这边是win环境,电脑上装的是py ...
- python开发基础教程
第一:python基础 第二:python异常处理类 第三:python装饰器 python常用的装饰器 第四:python发送邮件
- [Usaco2017 Feb]Why Did the Cow Cross the Road II (Gold)
Description 上下有两个长度为n.位置对应的序列A.B, 其中数的范围均为1~n.若abs(A[i]-B[j])<= 4,则A[i]与B[j]间可以连一条边. 现要求在边与边不相交的情 ...
- 题解报告:poj 2823 Sliding Window(单调队列)
Description An array of size n ≤ 106 is given to you. There is a sliding window of size k which is m ...
- 题解报告:hdu 1261 字串数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1261 Problem Description 一个A和两个B一共可以组成三种字符串:"ABB ...
- UML 活动图(转载)
活动图:用于表示系统中各种活动的次序,它的应用非常广泛,即可用来描述用例的工作流程,也可用来描述类中某个方法的操作行为.常用于表示业务流程,对系统功能建模,强调对象之间的控制流.活动图是由状态图变化而 ...