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

python unicode

2015-05-31 21:57 585 查看
[b]Python.org[/b]

首先感谢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:', u'0')
('type', <type 'unicode'>)
---------------------
after encode utf-8:
('value:', '0')
('type', <type 'str'>)
---------------------
then decode data back:
('value:', u'0')
('type', <type 'unicode'>)


[b]拓展[/b]

更便捷、完善的处理方式?

中文字符输入、输出
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: