Python 2.7 Data Type for Text Strings: Unicode and Str
2015-06-11 12:59
633 查看
The problem of encoding errors when writing programs in python 2.7 is the co-existence of Unicode type string and Str type string.
The "default" data type for text strings in python2.7 is Str type, which can only handle 8-bits ASCII characters correctly. But when it comes to handling non-ASCII characters, unicode type string may be used.
This results in a situation when a third-party package method return potentially two types of text string to dealing with both ASCII and non-ASCII type encoded data. An example is that in the a third-party method returns a Str type obj when there's only
pure ASCII encoding input, but returns a Unicode type obj whenever it encounters a Non-ASCII encoding.
The users of the package may not be clear which of the text string type the package method will return, or even not aware of the possibility that two kinds of return types may exist.
The "default" data type for text strings in python2.7 is Str type, which can only handle 8-bits ASCII characters correctly. But when it comes to handling non-ASCII characters, unicode type string may be used.
This results in a situation when a third-party package method return potentially two types of text string to dealing with both ASCII and non-ASCII type encoded data. An example is that in the a third-party method returns a Str type obj when there's only
pure ASCII encoding input, but returns a Unicode type obj whenever it encounters a Non-ASCII encoding.
The users of the package may not be clear which of the text string type the package method will return, or even not aware of the possibility that two kinds of return types may exist.
相关文章推荐
- W32 python+selenium环境配置
- python入门
- 网络端口的转发和重定向(Python)
- Python标准库13 循环器 (itertools)
- 10 Python Optimization Tips and Issues
- python selenium 总结
- python扩展
- python脚本积累
- python日志模块
- windows下python画图matplotlib
- Python 时间和日期模块的常用例子
- Python正则表达式
- Python WxPython 的安装以及使用
- Python WxPython 的安装以及使用
- python3 tkinter教程
- Python基础教程笔记——抽象
- Python基础教程笔记——基础知识
- Python基础教程笔记——条件,循环和其他语句
- Python 学习笔记4
- python学习笔记