1 #将Unicode转换成普通的Python字符串:"编码(encode)"
2 unicodestring = u"Hello world"
3 utf8string = unicodestring.encode("utf-8")
4 asciistring = unicodestring.encode("ascii")
5 isostring = unicodestring.encode("ISO-8859-1")
6 utf16string = unicodestring.encode("utf-16")
7
8
9 #将普通的Python字符串转换成Unicode: "解码(decode)"
10 plainstring1 = unicode(utf8string, "utf-8")
11 plainstring2 = unicode(asciistring, "ascii")
12 plainstring3 = unicode(isostring, "ISO-8859-1")
13 plainstring4 = unicode(utf16string, "utf-16")
14
15 assert plainstring1==plainstring2==plainstring3==plainstring4

python Unicode 编码解码的更多相关文章

  1. Unicode编码解码在线转换工具

    // Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...

  2. C# \uxxx Unicode编码解码

    /// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...

  3. Unicode 编码解码

    1. Regex.Unescape(str);返回Unicode解码,非Unicode直接返回 /// <summary>      /// 2.转为Unicode编码      /// ...

  4. Asp.Net \uxxx Unicode编码解码

    /// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...

  5. C# Unicode编码解码

    public static class CommpnHelpEx { /// <summary> /// unicode编码 /// </summary> /// <pa ...

  6. day06 python is == 编码 解码

    day06 python   一. is 和 == 的区别     == :比较, 判断, 比较的是值: 可以比较数字, 字符串, 列表, 元组, 字典,等     is :是 比较, 比较的是内存地 ...

  7. 10 python 初学(Python 的编码解码)

    Python 2 : ASCII Python 3 :Unicode

  8. opencv python图片编码解码

    cv2.imdecode()函数从指定的内存缓存中读取数据,并把数据转换(解码)成图像格式;主要用于从网络传输数据中恢复出图像.cv2.imencode()函数是将图片格式转换(编码)成流数据,赋值到 ...

  9. Python Base64编码解码

    import base64 str = '12345678'.encode('utf8') print(base64.b64encode(str).decode('utf8')) # 编码 接收的参数 ...

随机推荐

  1. [LeetCode] House Robber II 打家劫舍之二

    Note: This is an extension of House Robber. After robbing those houses on that street, the thief has ...

  2. NPOI操作EXCEL(三)——反射机制进行excel表格数据的解析

    我们先来回忆回忆上篇文章讲到的通过xml配置文件实现excel批量模板解析的整体思路: 1.对每个excel模板制定xml配置规则集,实现xml配置文件的解析服务 2.为每个excel模板制定DTO, ...

  3. 关于js解析的一点小问题

    先来看一下下面的一段代码有什么问题? <html><head><script src="./jquery.min.js"></script ...

  4. JQuery选择器

    动态修改样式 $("#div1").attr("display","block"); //有问题 $("#div1"). ...

  5. read properties

    读取配置文件在项目中使用频率很大,但是实际项目中各种人,各种用法,五花八门,往往是一种方式的各种变体,然很多种方式是其中一种方式的复杂化.今天我来总结下读取配置文件的集中方式及一些不能靠copy代码能 ...

  6. Block常用方法以及注意事项

    1. ViewController间传递数据 2. Block的@property必须定义为copy

  7. win7快捷键

    <1> Top 17 常规快捷键 在开始使用Win7中神奇的快捷键加速我们的电脑操作之前,先给大家介绍几个从Win2000到现在一直通用的"资源管理器"快捷键,权当作热 ...

  8. BZOJ 1221: [HNOI2001] 软件开发

    1221: [HNOI2001] 软件开发 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1428  Solved: 791[Submit][Stat ...

  9. PHP build notes - WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 3.0, min: 204, excluded: 3.0).

     WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 3.0, ...

  10. ActiveMQ_Mqtt的TCP丢包

    现象 Mqtt Consumer应该收到的消息少于预期,登录ActiveMQ的管理页面里的Topics,查看Messages Enqueued发现同样少于理应接收的数量. 定位问题 怀疑是TCP丢包, ...