首页 > 编程语言 > 详细

python unicode

时间:2015-05-31 23:00:13      阅读:391      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!