zoukankan      html  css  js  c++  java
  • python unicode

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

    拓展


    1. 更便捷、完善的处理方式?
    2. 中文字符输入、输出
  • 相关阅读:
    关键字: simpledateformat24小时 格式串
    浅谈DB2在线分析处理函数
    Java中的final关键字
    TestNG注解使用技巧
    java之静态方法,静态变量
    CssSelector之selenium元素定位
    收藏,常用正则表达式
    正则表达式小结
    [转]java中文乱码的解决
    多叉树结构:JSON数据解析(一)
  • 原文地址:https://www.cnblogs.com/dotdog/p/4542782.html
Copyright © 2011-2022 走看看