“将dict从一个api转换为另一个api的dict”python模块。

transmogrifydict的Python项目详细描述


跨语言信息技术

“将dict从一个api映射到另一个api的dict”python模块。

That dict is so cool...

TestsCoverage

TestsCoverage

TestsCoverage

TestsCoverage

TestsCoverage

Flake8

TestsCoverage

TestsCoverage

TestsCoverage

TestsCoverage

TestsCoverage

Flake8

方法

  • resolve_mapping_to_dict(mapping, source)-将值从source移动到返回的dict中,对路径和返回的键使用mapping

    fromtransmogrifydictimportresolve_mapping_to_dictmapping={'a':'d','b':'e','c':'f'}source={'d':1,'e':2,'f':3}resolve_mapping_to_dict(mapping,source)# {#     'a': 1,#     'b': 2,#     'c': 3,# }
  • resolve_path_to_value(source, path)-使用path作为指向所需值的指针,从source中获取值。有关路径字符串格式,请参见docstring。

    fromtransmogrifydictimportresolve_path_to_valuesource={'d':1,'e':2,'f':3}found,value=resolve_path_to_value(source,'e')print((found,value))# (True, 2)

pathmapping值格式

fromtransmogrifydictimportresolve_path_to_valuesource={'some-key':{'another-key':'123'}}# dot notation can be used to descend into dictionaries.resolve_path_to_value(source,'some-key.another-key')# (True, '123')source={'some-key':'{"another-key":"123"}'}# dot notation can also be used to descend into json strings that are dictionary likeresolve_path_to_value(source,'some-key.another-key')# (True, '123')source={'some-key':{'another-key':['1','2','3']}}# square brackets can be used to get specific indexes from a listresolve_path_to_value(source,'some-key.another-key[1]')# (True, '2')source={'some-key':{'another-key':[{'filter-key':'yeah','each-key':'a',},{'filter-key':'yeah','each-key':'b',},{'filter-key':'nah','each-key':'c',}]}}# dot notation can be used after square brackets if the list contains dict-like valuesresolve_path_to_value(source,'some-key.another-key[1].each-key')# (True, ['b']) # square brackets can be used to iterate over arrays to descend into the itemsresolve_path_to_value(source,'some-key.another-key[].each-key')# (True, ['a', 'b', 'c'])# when iterating over a list, a filter can be applied using [key=value]resolve_path_to_value(source,'some-key.another-key[filter-key=yeah].each-key')# (True, ['a', 'b'])source={'a-key':[{'b-key':{'c-key':1,'d-key':2,}},{'b-key':{'c-key':1,'d-key':3,}},{'b-key':{'c-key':0,'d-key':4,}}]}# tidle notation can be used to filter on sub keys of dict list items.resolve_path_to_value(source,'a-key[b-key~c-key=1].b-key.d-key')# (True, [2, 3, 4])# 

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java未从Facebook OAuth接收名字、姓氏和姓氏   我自己代码中的java ConcurrentModificationException   java在Android上获得单像素TIFF图像   java图形输出中的swing集成弹出窗口“通知”   将数据库表中的所有数据集插入jTable Java   java如何使用Hibernate获取不完整的集合?   打印无法从java连接到打印机   java使用分隔符拆分带引号的字符串   java Axis2禁用严格验证(wsdl2java中的Eosv)允许什么,如何使其更加严格?   java有人能帮我处理循环代码吗   java将JsonObject数组转换为整数   JavaXWiki扩展:检测事件空间创建   java如何设置图表的文本方向以使用poi旋转所有文本?   eche RecyclerView项的java Set自定义字体   java单元测试带有私有构造函数的spring组件,无需注入   用户界面如何在java中动态显示一组多个元素?   如何从java应用程序调用IDL(交互式数据语言)?   Java的内置库实现