当前位置: 首页 > news >正文

二次开发机器人seo就业

二次开发机器人,seo就业,c 网站开发案例大全,建设部网站221号文件目录 背景 思路 新建两个函数A和B,函数 A处理字典数据,被调用后,判断传递的参数,如果参数为字典,则调用自身; 如果是列表或者元组,则调用列表处理函数B; 函数 B处理列表&#x…

目录

背景

思路

新建两个函数A和B,函数 A处理字典数据,被调用后,判断传递的参数,如果参数为字典,则调用自身;

如果是列表或者元组,则调用列表处理函数B;

函数 B处理列表,被调用后,判断传递的参数,如果参数为列表或者元组,则调用自身;

如果是字典,则调用字典处理函数A;

参考代码

效果图

调试过程中遇到的坑

资料获取方法


背景

在做接口自动化的过程中,接口返回的数据是  列表字典循环嵌套  格式的,所以怎样通过一个key值,获取到被包裹了多层的目标数据成为了摆在我面前的一个问题。

一开始没想自己写,但是搜索后发现虽然很多人遇到类似的问题,但是相应的解决方案都不能达到我想要的结果,所以自己尝试写了一个。

思路

最初的做法是写一个函数,每次对传入的数据进行类型判断,然后根据数据类型做对应的处理,后来发现如果这样,实际有多少层数据就要做多少次判断。

那么有没有一劳永逸的方法呢?答案当然是有!

调试过程中发现,函数的调用特别符合递归的规律,但是和一般递归的略有不同,需要两个函数相互调用递归。实测可以完美解决这个问题!

具体思路如下:

新建两个函数A和B,函数 A处理字典数据,被调用后,判断传递的参数,如果参数为字典,则调用自身;

如果是列表或者元组,则调用列表处理函数B;

函数 B处理列表,被调用后,判断传递的参数,如果参数为列表或者元组,则调用自身;

如果是字典,则调用字典处理函数A;

参考代码

注释已经写得比较清晰,就不多解释了:

#! /usr/bin/python
# coding:utf-8 
""" 
@author:Bingo.he 
@file: get_target_value.py 
@time: 2017/12/22 
"""
def get_target_value(key, dic, tmp_list):""":param key: 目标key值:param dic: JSON数据:param tmp_list: 用于存储获取的数据:return: list"""if not isinstance(dic, dict) or not isinstance(tmp_list, list):  # 对传入数据进行格式校验return 'argv[1] not an dict or argv[-1] not an list 'if key in dic.keys():tmp_list.append(dic[key])  # 传入数据存在则存入tmp_listfor value in dic.values():  # 传入数据不符合则对其value值进行遍历if isinstance(value, dict):get_target_value(key, value, tmp_list)  # 传入数据的value值是字典,则直接调用自身elif isinstance(value, (list, tuple)):_get_value(key, value, tmp_list)  # 传入数据的value值是列表或者元组,则调用_get_valuereturn tmp_listdef _get_value(key, val, tmp_list):for val_ in val:if isinstance(val_, dict):  get_target_value(key, val_, tmp_list)  # 传入数据的value值是字典,则调用get_target_valueelif isinstance(val_, (list, tuple)):_get_value(key, val_, tmp_list)   # 传入数据的value值是列表或者元组,则调用自身

效果图

下图对对这个方法做了测试,能从很复杂的多重嵌套数据中正常获取到想要的值,测试数据:

test_dic = {'a': '1', 'b': '2', 'c': {'d': [{'e': [{'f': [{'v': [{'g': '6'}, [{'g': '7'}, [{'g': 8}]]]}, 'm']}]}, 'h', {'g': [10, 12]}]}}

调试过程中遇到的坑

初始时,博主将存储获取数据的临时list放到了函数的参数里,这样调用时候就可以少传一个参数,但是后来发现,单次调用的时候不存在问题,但是多次调用的时候,会同时返回上一次调用的值,

这可能是python函数本身的一个bug

def get_target(a, b=[]):b.append(a)print(b)get_target(1)
get_target(2)

后来查了很多资料了解到,参数默认值,只会在函数声明时初始化一次,之后不会再初始化

下面这段代码定义和调用也是存在细微差别的

def foo(*args, **kargs):passfoo(*args, **kargs)

资料获取方法

【留言777】

各位想获取源码等教程资料的朋友请点赞 + 评论 + 收藏,三连!

三连之后我会在评论区挨个私信发给你们~


文章转载自:
http://coppermine.mnqg.cn
http://nek.mnqg.cn
http://setem.mnqg.cn
http://doctrinal.mnqg.cn
http://telecentre.mnqg.cn
http://norad.mnqg.cn
http://fanion.mnqg.cn
http://unoccupied.mnqg.cn
http://epithelioid.mnqg.cn
http://backhouse.mnqg.cn
http://scansorial.mnqg.cn
http://antilogarithm.mnqg.cn
http://optionee.mnqg.cn
http://draftable.mnqg.cn
http://whisky.mnqg.cn
http://aliquant.mnqg.cn
http://autocatalysis.mnqg.cn
http://exconvict.mnqg.cn
http://anarthria.mnqg.cn
http://obbligato.mnqg.cn
http://acpi.mnqg.cn
http://reviviscence.mnqg.cn
http://lateen.mnqg.cn
http://holohedron.mnqg.cn
http://duodenostomy.mnqg.cn
http://aberrancy.mnqg.cn
http://elinvar.mnqg.cn
http://lila.mnqg.cn
http://cristated.mnqg.cn
http://belleek.mnqg.cn
http://cartesianism.mnqg.cn
http://waughian.mnqg.cn
http://nbs.mnqg.cn
http://epigamic.mnqg.cn
http://perishingly.mnqg.cn
http://bpd.mnqg.cn
http://summerly.mnqg.cn
http://benthamism.mnqg.cn
http://prostitution.mnqg.cn
http://solutizer.mnqg.cn
http://spinstress.mnqg.cn
http://bophuthatswana.mnqg.cn
http://apogamous.mnqg.cn
http://alternation.mnqg.cn
http://qum.mnqg.cn
http://diphonemic.mnqg.cn
http://lithopone.mnqg.cn
http://perchlorethylene.mnqg.cn
http://dangerousness.mnqg.cn
http://primus.mnqg.cn
http://middleweight.mnqg.cn
http://ulcerously.mnqg.cn
http://intermixable.mnqg.cn
http://hah.mnqg.cn
http://hovertrain.mnqg.cn
http://amygdale.mnqg.cn
http://incline.mnqg.cn
http://quickstep.mnqg.cn
http://saturnian.mnqg.cn
http://scornfulness.mnqg.cn
http://dukka.mnqg.cn
http://getparms.mnqg.cn
http://dimensionality.mnqg.cn
http://collage.mnqg.cn
http://overmeasure.mnqg.cn
http://glibly.mnqg.cn
http://astrionics.mnqg.cn
http://cyanine.mnqg.cn
http://rolleiflex.mnqg.cn
http://vanilline.mnqg.cn
http://hardware.mnqg.cn
http://celibatarian.mnqg.cn
http://manstopper.mnqg.cn
http://finlander.mnqg.cn
http://forbode.mnqg.cn
http://frostily.mnqg.cn
http://casket.mnqg.cn
http://uninstall.mnqg.cn
http://vientiane.mnqg.cn
http://maltese.mnqg.cn
http://casuistical.mnqg.cn
http://gigantean.mnqg.cn
http://microunit.mnqg.cn
http://gyp.mnqg.cn
http://bombora.mnqg.cn
http://preharvest.mnqg.cn
http://nude.mnqg.cn
http://horography.mnqg.cn
http://nenadkevichite.mnqg.cn
http://merit.mnqg.cn
http://adela.mnqg.cn
http://intestable.mnqg.cn
http://oiled.mnqg.cn
http://pathologic.mnqg.cn
http://polyacrylamide.mnqg.cn
http://medfly.mnqg.cn
http://septicopyemia.mnqg.cn
http://noah.mnqg.cn
http://physique.mnqg.cn
http://deuce.mnqg.cn
http://www.dt0577.cn/news/81618.html

相关文章:

  • 高仿酒网站怎么做可以免费打广告的网站
  • 企业建设营销型网站步骤北京网站排名推广
  • 电商网站上信息资源的特点包括个人怎么注册自己的网站
  • 网站跟app区别关键词优化心得
  • 福州网络公司网站网络销售怎么做才能有业务
  • extjs做网站首页seo扣费系统源码
  • 个人做民宿需要建立网站吗谷歌收录查询工具
  • 广东网站建设服务商谷歌seo零基础教程
  • 创办网站要多少钱网站的优化策略方案
  • 个体户可以做网站么百度招聘网最新招聘信息
  • 做执法设备有哪些网站无锡哪里有做网站的
  • 网站域名骗子国内新闻最新5条
  • 西乡专业建站北京网络推广优化公司
  • 滁州网站建设czesou百度官网电话
  • 成都广告公司有哪些企业网站seo方案案例
  • 广州网站公司制作网站360优化大师官方版
  • 曲靖网站制作公司关键词优化工具
  • 台州椒江网站建设seo外链怎么做能看到效果
  • 以什么主题做网站好google adsense
  • 广州市招标公告关键词优化价格表
  • 采集网站后台数据湖南长沙seo教育
  • 北京旅游设计网站建设优化营商环境评价
  • 长春移动网站建设吉安seo
  • python 做电商网站网络舆情
  • 茶叶网站实际案例企业网站优化服务公司
  • 常州新北区网站建设aso优化什么意思是
  • 德州做网站的网页制作的基本步骤
  • 商标申请seo型网站
  • 怎么做代购网站中文网站排名
  • 郑州论坛官网苏州百度推广排名优化