1 #!coding: utf-8 2 s = "特斯拉" 3 s_to_unicode = s.decode("utf-8") 4 unicode_to_gbk = s_to_unicode.encode("gbk") 5 print s 6 print ("unicode:", s_to_unicode) 7 print ("gbk", unicode_to_gbk) 8 9 gbk_to_unicode = unicode_to_gbk.decode("gbk")10 unicode_to_utf8 = gbk_to_unicode.encode("utf-8")11 print (gbk_to_unicode)12 print (unicode_to_utf8)
1 输出结果2 [root@python]# python uncode.py3 特斯拉4 ('unicode:', u'\u7279\u65af\u62c9')5 ('gbk', '\xcc\xd8\xcb\xb9\xc0\xad')6 特斯拉7 特斯拉