码迷,mamicode.com
首页 > 编程语言 > 详细

python unicode

时间:2015-05-31 23:02:10      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

 

 

Python.org


 

首先感谢python完善的文档,文档从1968年 the American Standard Code (ASCII)开始讲述。

 

print(type(response))
print(type(response[ERRORCODE]))
print(type(response[RESULT]))

类型分别如下:

<type dict>
<type unicode>
<type unicode>

 

字典类型(以后把这个栗子再完善点):

dict_demo = {
    "ERRORCODE": unicode(0),
    "RESULT": {
        "accountID": "abc",
        "nickName": "123",
        "tuple": (1,2,3),
        "list": [1,2,3],
        "set":{1,3},
        "dict":{1:1,2:"what?"}
    }
}

最典型的的是根据ERRORCODE的值来判断是否要取“获得“的结果,

origin_data = dict_demo[ERRORCODE]
print("---------------------")
print("before encode utf-8:")
print("value:", origin_data)
print("type", type(origin_data))
utf8_version = origin_data.encode(utf-8)
print("---------------------")
print("after encode utf-8:")
print("value:", utf8_version)
print("type", type(utf8_version))
decode_data = utf8_version.decode(utf-8)
print("---------------------")
print("then decode data back:")
print("value:", decode_data)
print("type", type(decode_data))

结果如下:

---------------------
before encode utf-8:
(value:, u0)
(type, <type unicode>)
---------------------
after encode utf-8:
(value:, 0)
(type, <type str>)
---------------------
then decode data back:
(value:, u0)
(type, <type unicode>)

 

拓展


 

  1. 更便捷、完善的处理方式?
  2. 中文字符输入、输出

 

python unicode

标签:

原文地址:http://www.cnblogs.com/dotdog/p/4542782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!