python 中文 str 以及 unicode区别和互相转换
来源:互联网 发布:马鞍山知谷教育图片 编辑:程序博客网 时间:2024/06/12 08:23
看了 http://www.jianshu.com/p/53bb448fe85b# 这篇兄弟的文章, 深有感触,自己做做测试试试:
加不加u是有区别的哦
unicode到string 只需要encode一下,尤其在我们读取unicode的文本,然后需要进行字符拼接的时候,本身unicode无法进行拼接
string decode之后就是unicode了
string和string, 以及 unicode和unicode 可以进行拼接
- 但是string和unicode在一起就有问题了
In [38]: In [38]: In [38]: a1 + b1---------------------------------------------------------------------------UnicodeDecodeError Traceback (most recent call last)<ipython-input-38-ffd3f356020c> in <module>()----> 1 a1 + b1UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)
我们该怎么办呢
In [39]: a1.decode('utf-8') + b1Out[39]: u'\u5927\u4e2d'In [40]: In [40]: In [40]: a1 + b1.encode("utf-8")Out[40]: '\xe5\xa4\xa7\xe4\xb8\xad'
0 0
- python 中文 str 以及 unicode区别和互相转换
- python中str和list互相转换
- Python str unicode转换
- java 中文和Unicode码 互相转换
- python undecode和str区别与转换
- python的str和unicode以及编码的问题
- java程序实现Unicode码和中文互相转换笔记
- java程序实现Unicode码和中文互相转换笔记
- 了解python中bytes,str和unicode的区别
- python 编码unicode 和 str
- 中文和Unicode互相转化
- 中文和Unicode互相转化
- Python中文处理:str与unicode
- 字符串和unicode互相转换
- python,unicode转换中文,中文转换unicode
- java实现中文,unicode互相转换
- 《python》 str 和 list 转换 以及eval()函数
- python 字符串(str)和列表(list)的互相转换
- hdu 1006 Tick and Tick
- 算法基础之归并排序
- CS231n Assignment1--Q3
- Builder模式
- JVM的堆和栈以及GC算法的介绍
- python 中文 str 以及 unicode区别和互相转换
- MFC—— 窗口句柄获取
- 最新版本的Struts2+Spring4+Hibernate4三大框架整合(截止2014-10-15)
- LeetCode 380. Insert Delete GetRandom O(1) 题解
- 《HeadFirst设计模式》读书笔记-第1章-策略模式
- 泽泽在巴西(jzoj普及组模拟第三题)(超难)
- 模拟队列
- cuda编程
- 中国商业环境发展的五个阶段浅析