regx json fullpath
时间:2019-11-06
本文章向大家介绍regx json fullpath ,主要包括regx json fullpath 使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
from collections import OrderedDict import jsonpath_rw import json from future.moves import collections A={"c":"ddd","app":999,"phone":18676743129,"user":"张胜男","tr":{"last":{"need":False}}} order=OrderedDict() # print(sorted(A.items(),key=lambda x:x[0],reverse=True)) def order_define(o): if isinstance(o,dict): orders=dict(sorted(o.items(),key=lambda x:x[0],reverse=True)) print(orders) # data = { # "glossary": { # "title": "example glossary", # "GlossDiv": { # "title": "S", # "GlossList": { # "GlossEntry": { # "ID": "SGML", # "SortAs": "SGML", # "GlossTerm": "Standard", # "Acronym": "SGML", # "Abbrev": "ISO ", # "GlossDef": { # "para": "DocBook.", # "GlossSeeAlso": ["GML", "XML"] # }, # "GlossSee": "markup" # } # } # } # } # } data={ "initiator": { "role": "guest", "party_id":9997 }, "job_parameters": { "work_mode": 1 }, "role": { "guest": [ 9997 ], "host": [ 9997 ], "arbiter": [ 9997 ] }, "role_parameters": { "guest": { "args": { "data": { "train_data": [ { "name": "breast_guest", "namespace": "breast_guest" } ] } }, "dataio_0": { "with_label": [True], "label_name": ["y"], "label_type": ["int"], "output_format": ["dense"], "missing_fill": [True], "outlier_replace": [True] }, "feature_scale_0": { "method": ["min_max_scale"] }, "hetero_feature_binning_0": { "method": ["quantile"], "compress_thres": [10000], "head_size": [10000], "error": [0.001], "bin_num": [10], "cols": [-1], "adjustment_factor": [0.5], "local_only": [False], "transform_param": { "transform_cols": [-1], "transform_type": ["bin_num"] } }, "hetero_feature_selection_0": { "select_cols": [-1], "filter_methods": [[ "unique_value", "iv_value_thres", "coefficient_of_variation_value_thres", "iv_percentile", "outlier_cols" ]], "local_only": [False], "unique_param": { "eps": [1e-6] }, "iv_value_param": { "value_threshold": [1.0] }, "iv_percentile_param": { "percentile_threshold": [0.9] }, "variance_coe_param": { "value_threshold": [0.3] }, "outlier_param": { "percentile": [0.95], "upper_threshold": [10] } }, "evaluation_0": { "eval_type": ["binary"], "pos_label": [1] } }, "host": { "args": { "data": { "train_data": [ { "name": "breast_host", "namespace": "breast_host" } ] } }, "dataio_0": { "with_label": [False], "output_format": ["dense"], "outlier_replace": [True] }, "feature_scale_0": { "method": ["standard_scale"], "need_run": [False] }, "hetero_feature_binning_0": { "method": ["quantile"], "compress_thres": [10000], "head_size": [10000], "error": [0.001], "bin_num": [10], "cols": [-1], "adjustment_factor": [0.5], "local_only": [False], "transform_param": { "transform_cols": [-1], "transform_type": ["bin_num"] } }, "hetero_feature_selection_0": { "select_cols": [-1], "filter_methods": [[ "unique_value", "iv_value_thres", "coefficient_of_variation_value_thres", "iv_percentile", "outlier_cols" ]], "local_only": [False], "unique_param": { "eps": [1e-6] }, "iv_value_param": { "value_threshold": [1.0] }, "iv_percentile_param": { "percentile_threshold": [0.9] }, "variance_coe_param": { "value_threshold": [0.3] }, "outlier_param": { "percentile": [0.95], "upper_threshold": [10] } }, "evaluation_0": { "need_run": [True] } } }, "algorithm_parameters": { "feature_scale_0": { "need_run": True }, "hetero_feature_binning_0": { "need_run": True }, "hetero_feature_selection_0": { "need_run": True }, "hetero_lr_0": { "penalty": "L2", "optimizer": "rmsprop", "eps": 1e-5, "alpha": 0.01, "max_iter": 10, "converge_func": "diff", "batch_size": -1, "learning_rate": 0.15, "init_param": { "init_method": "random_uniform" }, "cv_param": { "n_splits": 5, "shuffle": False, "random_seed": 103, "need_cv": False } } } } import collections import warnings warnings.filterwarnings("ignore") def get_paths(source): paths = [] if isinstance(source, collections.MutableMapping): # found a dict-like structure... for k, v in source.items(): # iterate over it; Python 2.x: source.iteritems() paths.append([k]) # add the current child path paths += [[k] + x for x in get_paths(v)] # get sub-paths, extend with the current # else, check if a list-like structure, remove if you don't want list paths included elif isinstance(source, collections.Sequence) and not isinstance(source, str): # Python 2.x: use basestring instead of str ^ for i, v in enumerate(source): paths.append([i]) paths += [[i] + x for x in get_paths(v)] # get sub-paths, extend with the current return paths def cast_full_path(path_list,dictvariable_name:str): path="" for i in path_list: if isinstance(i,int): path=path+'[{}]'.format(i) else: path =path+"['%s']"%i full_path= path return full_path def str_path(data): path_str=[] paths=get_paths(data) for i in paths: res='.'.join([str(j) for j in i]) path_str.append(res) return path_str # for i in path_str: # print(i) def full_path_list(quantile_list,dictvar_name): paths_list=[] for i in quantile_list: v=cast_full_path(i,"%s"%dictvar_name) paths_list.append(v) return paths_list def judge_path(key:str,regx_index=-1): res=[] it=full_path_list(get_paths(data),"data") for i in it: var=i.replace('[','.').replace(']','.').strip('.').replace('..','.').replace("'",'').split('.') if key==var[-1]: print("matchs join strpath is:\n %s" % '.'.join(var)) res.append(i) if regx_index !=-1: print("last return:\n%s "%res[regx_index]) return res[regx_index] elif regx_index==-1: print("last return:\n%s " % res) return res if __name__ == '__main__': # k=full_path_list(get_paths(data),"data") # for i in k: # print(i) judge_path("name") # st="['role_parameters']['guest']['hetero_feature_selection_0']['iv_value_param']['value_threshold'][0]" # aa=st.replace('[','.').replace(']','.').strip('.').replace('..','.').replace("'",'').split('.')
.
原文地址:https://www.cnblogs.com/SunshineKimi/p/11808167.html
- Spring Boot 中使用 Redis
- 使用 Jedis 连接操作 Redis
- 浅析ReDoS的原理与实践
- 使用 Executors,ThreadPoolExecutor,创建线程池,源码分析理解
- CentOS+Nginx+Tomcat搭建高性能负载均衡集群
- Java 四种线程池的使用
- 搭建 Jenkins-2.83 服务,部署 spring boot 项目
- Spring Boot 中使用 Java API 调用 lucene
- Spring Boot 中使用 Java API 调用 Elasticsearch
- Spring Boot 中使用 公共配置
- WebView 和 JS 交互,如何将 Java 对象和 List 传值给 JS ?
- Spring Boot 中使用 LogBack 配置
- Spring Boot 中使用 RabbitMQ
- 手把手教你dubbo怎么用?
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Python中设置指定窗口为前台活动窗口(最顶层窗口)win32gui
- 关于pandas.eval使用的一些问题。
- Flutter基础widgets教程-Slider篇
- 带你认识Pytest(三)
- Additive Powers-of-Two (APoT) Quantization:硬件友好的非均匀量化方法
- Flutter基础widgets教程-SnackBar篇
- Redash 二开 - 后端环境搭建
- Flutter基础widgets教程-Stepper篇
- Flutter基础widgets教程-Switch篇
- 13.深入k8s:Pod 水平自动扩缩HPA及其源码分析
- python 协程新版
- 14.深入k8s:kube-proxy ipvs及其源码分析
- netty
- Flutter基础widgets教程-TabBar篇
- 厉害了!华为将发布国产编程语言,打破国外垄断!