One
Crawling web information in crawlers often requires converting a similar "\u4eba\u751f\u82e6\u77ed\uff0cpy\u662f\u5cb8" to Chinese, which is actually Unicode's Chinese encoding. The following methods can be used to convert:
1.
1 >>> s = u'\u4eba\u751f\u82e6\u77ed\uff0cpy\u662f\u5cb8'2 Print s 3 Life is short, py is shore
2.
1 >>> s = R'\u4eba\u751f\u82e6\u77ed\uff0cpy\u662f\u5cb8'2 >>> s = s.decode ('unicode_escape')3print s 4 Life is short, py is shore
Two
In addition, the Python2 character encoding problem often encounters "unicodeencodeerror: ' ASCII ' codec can ' t encode characters in position 0-5: Ordinal not in Ran code error for GE (+).
The following methods can usually be used to solve the problem:
1 Import SYS 2 Reload (SYS) 3 sys.setdefaultencoding ('utf-8')
This method changes the default encoding ASCII of Python2 to Utf-8. But this method is not once and for all, and may cause some code behavior to become weird.
You can refer to this connection: http://blog.ernest.me/post/python-setdefaultencoding-unicode-bytes
Python Unicode to Chinese and conversion default encoding