• python接口自动化测试十:字典、字符串、json之间的简单处理


    python接口自动化测试十:字典、字符串、json之间的简单处理

     

    # 字典
    = None    # None = null
    = False   # boolean
    c, d 12, 10.6 # int float
    = 'asdd'  # str
    = ['s''e']  # list,数组,可增删改查
    = ('a''s''f') # 元组(tuple),只能查

     

    # 字典
    = {
    #   键:值
        '': '',
        '': ''
        }

    # 字典
    # dict      key: value   key是唯一的,无序的
    = {
        's': 
    12,
        'f': False,
        2: 'd',
        'r': 't',
        'sd': ['gf''rt'' ew'],
        'rt': ('rte''ewr'),
        'ru': {
                'rty': 'fghg'
    ,
                'dfs': 'yjtujyt'
                }
        }
    # print(h)
    print(h['ru'])      # 取出指定的key为ru的值

     

    # 取出所有的key
    keys h.keys()
    print(keys)

     

    遍历所有的key
    for i in list(keys):
        print('%s = %s'%(i, h[i]))

     

    abc = {'aa': 'dd''bb': 'th'}
    print(abc)
    print(type(abc))    # 查看abc的数据类型
    aaa str(abc)      # 字典转str
    print(type(aaa))
    print(aaa)

     

    bbb eval(aaa)     # str转字典
    print(type(bbb))
    print(bbb)

     

    # 字符串转字典

    bbb eval(aaa)

    print(type(bbb))

    print(bbb)

    # 字典转json:   json本质是字符串,只是按一定规则转换的
    d_json = json.dumps(h)
    print(d_json)
    print(type(d_json))
    # json(str)转字典  : 把json格式转换成字典格式
    json_dict = json.loads(d_json)
    print(type(json_dict))
    print(json_dict)
    创作不易,转摘请标明出处。如果有意一起探讨测试相关技能可加博主QQ 771268289
  • 相关阅读:
    pandas取值
    pandas 基本操作
    Pandas三个数据结构
    pandas.Series
    scipy线性模块liner(linalg)
    numpy meshgrid函数
    scipy插值interpolation
    scipy优化器optimizer
    scipy积分 integral
    8086汇编 Loop 指令
  • 原文地址:https://www.cnblogs.com/dwdw/p/9553087.html
Copyright © 2020-2023  润新知