您的位置:首页 > 编程语言 > Python开发

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: