python str方法 等于执行encode utf-8 无论是在ipython还是原生Python
来源:互联网 发布:魔兽1.12数据库 声望 编辑:程序博客网 时间:2024/06/06 09:11
对于unciode 类型来说,对他执行一次 str() 相当于执行unciode.encode("utf-8")
无论是在linux还是在windows
如图所示
代码如下
>>> import sys>>> reload(sys)<module 'sys' (built-in)>>>> sys.setdefaultencoding("utf-8")>>>>>> a = u"中">>>>>> au'\u4e2d'>>>>>> str(a)'\xe4\xb8\xad'>>>>>> a.encode("utf-8")'\xe4\xb8\xad'>>>>>> a.encode("gbk")'\xd6\xd0'>>>>>>
所以以后在对于 unicode 需要编码utf-8的情况下,就可以简写成str
(上面这样是都可以输入,但是如果print, 要对应上平台编码才能正常显示)
阅读全文
0 0
- python str方法 等于执行encode utf-8 无论是在ipython还是原生Python
- python的str()对于unicode来说并不等于encode utf-8 不能简写
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- python的str,unicode对象的encode和decode方法
- 【python】str,unicode对象的encode和decode方法
- python中 encode,decode,unicode,utf-8
- python str bytes unicode utf-8 学习
- 在python中判断字符串是str还是unicode
- Python: .encode方法
- python写入mysql时候 出现'latin-1' codec can't encode character 问题解决方法 以及python设置utf-8
- Python编码相关问题 Unicode UTF-8 encode() decode()
- python-str方法使用
- python str 方法
- Python str.split方法
- HDU 2444 The Accomodation of Students (二分图匹配+匈牙利算法+bfs判断是否为二分图)
- 大端模式、小端模式及其在Qt中的转换
- makefile作用
- ST表模板(维护区间最大值)
- HDU 3507 Print Article
- python str方法 等于执行encode utf-8 无论是在ipython还是原生Python
- Cannot refer to a non-final variable response inside an inner class defined in a different method
- System V共享内存
- Kubernetes入门指南:部署一个Node.js Docker应用 — SitePoint
- [声明]Hallmeow's cnblog
- MySQL索引优化
- 剑指offer--二叉树的下一个结点
- 总结
- 深拷贝和浅拷贝问题