随笔分类 -  python

摘要:lambda的简单使用: func = lambda a1, a2: a1 + a2 func1 = lambda a3: a3/2 print(func(100, 200)) # 运行结果:300 print(func1(4)) # 运行结果:2.0 不使用lambda时的写法: def func 阅读全文
posted @ 2023-06-08 15:56 奔奔-武 阅读(119) 评论(0) 推荐(0)
摘要:1、使用allure serve查看报告: cmd窗口下输入:allure serve 报告目录 提示:allure-results does not exists 将生成的链接地址在浏览器中打开,报告为空: 2、使用allure的其它命令打开: cmd窗口输入:allure generate al 阅读全文
posted @ 2021-05-28 13:47 奔奔-武 阅读(4627) 评论(0) 推荐(0)
摘要:1、打开cmd命令窗口 2、输入:jupyter notebook --generate-config,回车后会提示jupyter_lab_config.py文件的位置,如图: 3、打开jupyter_lab_config.py文件,添加以下代码: import webbrowser webbrow 阅读全文
posted @ 2021-05-27 10:26 奔奔-武 阅读(3323) 评论(0) 推荐(0)
摘要:一、安装 requests和jsonpath 模块 安装命令:pip install requests pip install jsonpath 二、requests 处理常见的接口请求参数类型 1、表单类型的参数:1)请求参数类型:content-type: application/x-www-f 阅读全文
posted @ 2020-11-03 13:28 奔奔-武 阅读(6498) 评论(0) 推荐(0)
摘要:需要安装的第三方库: pip install -i https://pypi.douban.com/simple wordcloud pip install -i https://pypi.douban.com/simple jieba 需要解析的文字,放到了word.txt文本中: 1. 根据软件 阅读全文
posted @ 2020-10-27 16:19 奔奔-武 阅读(995) 评论(0) 推荐(0)
摘要:它是 Python 内置的 HTTP 请求库,也就是说我们不需要额外安装即可使用 示例代码如下: 1 from urllib import request, parse 2 url = 'https://XX.XXXX.com/XX/XX/uaa/login' 3 headers = { 4 "x- 阅读全文
posted @ 2020-09-23 10:59 奔奔-武 阅读(201) 评论(0) 推荐(0)
摘要:使用python随机生成20位的数字+大写字母的密码: import random, string passwd = [] for i in range(20): if random.randint(0, 1): letter = random.choice(string.ascii_upperca 阅读全文
posted @ 2020-08-26 17:02 奔奔-武 阅读(2641) 评论(0) 推荐(0)
摘要:如下代码: # 默认值如果是可变的数据类型. 每次使用的时候都是同一个 def extendList(val, list=[]): print(id(list)) list.append(val) return list list1 = extendList(10) list2 = extendLi 阅读全文
posted @ 2020-07-29 17:02 奔奔-武 阅读(196) 评论(0) 推荐(0)
摘要:global: 在局部访问全局中的内容 nonlocal: 在局部寻找外层函数中离他最近的那个变量 globals() 查看全局中的内容 locals() 查看当前作用域中的内容 1、global的使用: # 全局变量本身就是不安全的, 不能随意修改, 可以使用闭包 a = 10 def func( 阅读全文
posted @ 2020-07-23 11:04 奔奔-武 阅读(622) 评论(0) 推荐(0)
摘要:举例说明: # 引入copy模块 import copy lst1 = [1, 2, 3, ["a", "b"]] # 赋值操作 lst2 = lst1 # 切片操作,会产生新的列表-浅拷贝 lst3 = lst1[:] lst4 = lst1.copy() lst5 = copy.deepcopy 阅读全文
posted @ 2020-06-28 15:56 奔奔-武 阅读(197) 评论(0) 推荐(0)
摘要:字符串方法的操作:capitalize、upper、lower、swapcase、title、center、expandtabs、replace等 # TODO:字符串是不可变对象, 所以任何操作对原字符串不会有任何影响 str = "python⽜BA" # 首字母大写 res = str.cap 阅读全文
posted @ 2020-06-11 13:21 奔奔-武 阅读(167) 评论(0) 推荐(0)
摘要:字符串切割函数split,以及需要留意的深坑! # 字符串切割 str = "我的昵称是奔奔,我的年龄是18,我的爱好是python" res = str.split(",") print(res) # 指定切割次数 res = str.split(",", 1) print(res) # TODO 阅读全文
posted @ 2020-06-11 11:39 奔奔-武 阅读(2165) 评论(0) 推荐(0)
摘要:int类型转换为bool类型时,0为False,非0为True str类型转换为bool类型时,空字符串和None为False,不空为True 以下为代码示例: 1 # int转换为bool 2 # 0是False 3 print(bool(0)) 4 # 非0是True 5 print(bool( 阅读全文
posted @ 2020-06-10 11:36 奔奔-武 阅读(14194) 评论(0) 推荐(0)
摘要:1 name = input("请输入昵称:") 2 age = input("请输入年龄:") 3 money = input("请输入年薪:") 4 hobby = input("请输入兴趣:") 5 6 # 变量赋值 7 print("""**************** 8 姓名:{nick 阅读全文
posted @ 2020-05-26 10:36 奔奔-武 阅读(1543) 评论(0) 推荐(0)
摘要:1 from collections import Counter 2 3 a = [1, 2, 3, 4, 3, 2, "奔奔", "benben", "奔奔"] 4 b = dict(Counter(a)) 5 # 只展示重复元素 6 print ([key for key,value in b 阅读全文
posted @ 2020-04-20 17:11 奔奔-武 阅读(8407) 评论(0) 推荐(1)
摘要:运行测试套件生成报告时,每次都需要执行hrun命令,再加上参数,实在是不方便,这次将运行写到run.py文件中,直接运行该py文件,即可运行并生成测试报告: # -*- coding: utf-8 -*- # @Time : 2020/3/18 23:00 # @Author : benben # 阅读全文
posted @ 2020-03-18 23:00 奔奔-武 阅读(2142) 评论(0) 推荐(0)
摘要:本实例中通过获取登录接口返回的token,将token值传到获取项目列表的请求头中,实现关联参数的应用: 1、.env中定义BASE_URL、USERNAME、PASSWORD三个变量值: BASE_URL=http://127.0.0.1:8000 USERNAME=benben PASSWORD 阅读全文
posted @ 2020-03-18 22:12 奔奔-武 阅读(1652) 评论(0) 推荐(0)
摘要:还是以本地搭建的接口测试平台的登录接口为例,发送请求,生成报告,查看结果等一系列操作,代码都是经过本地调试,运行通过的: 1、api目录下的demo_api.yml代码: name: 登录接口 base_url: ${ENV(BASE_URL)} variables: username: $user 阅读全文
posted @ 2020-03-18 21:41 奔奔-武 阅读(3155) 评论(0) 推荐(1)
摘要:接上一篇文章,在case2中,设置一个variables变量,然后再用这个variables变量去进行判断,预期结果中值显示是:LazyString($变量key) 代码截图: 运行结果: 修改测试报告html,如图: 再次运行: 同样,扩展模板extend-theme-template.html中 阅读全文
posted @ 2020-03-18 19:28 奔奔-武 阅读(629) 评论(2) 推荐(0)
摘要:创建项目时,默认会自动生成一个debugtalk.py文件,可以在该文件中写函数,获取接口请求中需要的数据。 本次代码中只是分别定义获取username和password的函数,用于返回登录接口中需要用的参数。 调用debugtalk.py文件中函数的方式:${函数名(参数)} 1、debugtal 阅读全文
posted @ 2020-03-17 23:27 奔奔-武 阅读(854) 评论(0) 推荐(0)