随笔分类 -  Python(语言)

摘要:(列表)和(字典)转字符串,可以使用同一个方法, 如果(字符串)是列表格式,则系统自动转换为列表, 如果是字典格式,则自动转换为字典 方法一:通过eval转换:eval方法虽然没有转换问题,但存在安全性问题,因为eval不仅能解析数据类型还能解析一些恶意输入命令,可能造成不好的影响 user = ' 阅读全文
posted @ 2022-08-28 22:11 博无止境 阅读(181) 评论(0) 推荐(0) 编辑
摘要:指定下标替换字符串 def replace_char(old_string, char, index): ''' 字符串按索引位置替换字符 ''' old_string = str(old_string) # 新的字符串 = 老字符串[:要替换的索引位置] + 替换成的目标字符 + 老字符串[要替换 阅读全文
posted @ 2022-08-20 23:32 博无止境 阅读(1378) 评论(0) 推荐(0) 编辑
摘要:定义一个参数:a ="abcdef" a.index()#找下标 a.find()#找下标 两者之间的区别: print(a.index("b1"))#如果找元素不存在,会报错 print(a.find("b1"))#如果找元素不存在,会返回-1 阅读全文
posted @ 2022-08-20 20:33 博无止境 阅读(464) 评论(0) 推荐(0) 编辑
摘要:将sql语句写进python时 ,会出现格式不正确的情况。少量sql还可以改, 但是如果sql语句量大时就无法改了 解决方法:直接用三引号概括起来即可,引号里面可以无视sql语法格式 阅读全文
posted @ 2022-06-24 14:59 博无止境 阅读(275) 评论(0) 推荐(0) 编辑
摘要:在实际python接口自动化项目中, 可能有多个py用例文件, 当你需要将用例文件1的变量, 需要传入用例文件3,或者需要传入更多的用例文件中, 使用yaml文件来保存这些变量是非常方便实用的 如何做? 1. 首先在项目根路径下新建一个 extract.yaml 文件。(名称可以自定义) .2 然后 阅读全文
posted @ 2022-05-13 22:13 博无止境 阅读(1348) 评论(0) 推荐(0) 编辑
摘要:很多同伴在执行py文件时, 用的都是函数入口运行,如下 if __name__ == '__main__': pytest.main(['-s']) 因为我们在学习python时用的也都是此方法,但是无论是接口自动化还是web自动化,项目上一般都是使用 pytest.ini 文件配置运行方法。以下介 阅读全文
posted @ 2022-05-09 22:57 博无止境 阅读(237) 评论(0) 推荐(0) 编辑
摘要:也许有人觉得这样的问题很愚蠢,以至于关于这个的问题网上讲解很少,一般上来都是教你如何使用,但对于一个刚踏入python 接口自动化 的小白来说, 越简单的问题越让人难以理解。 requirements.txt 文件解释: 这个文件是一个用于一次性保存在python包的一个文件,通常我们在下载包时,例 阅读全文
posted @ 2022-05-08 10:04 博无止境 阅读(4557) 评论(0) 推荐(0) 编辑
摘要:安装: pip install openpyxl 读取: 一行行读取 from openpyxl import load_workbook # 读取excel方法 def read_excel(): path = r"D:\Users\72036454\Desktop\python_automati 阅读全文
posted @ 2022-04-25 20:26 博无止境 阅读(893) 评论(0) 推荐(1) 编辑
摘要:问题:有一组字符串,我想用某个符号来分隔它们。如下可以看到, 我用逗号将它们分隔了 a = "你,好,吗" b = a.split(",") print(b) 执行结果>>> ['你', '好', '吗'] 使用别的符号隔开也可以,只要是字符串中出现的任何文字或字符、都可以作为分隔符,甚至换行符空格 阅读全文
posted @ 2022-04-01 22:36 博无止境 阅读(426) 评论(0) 推荐(0) 编辑
摘要:pytest-rerunfailures pytest-rerunfailures是属于pytest的插件,通常用来执行用例失败后重新执行。 安装:pip install pytest-rerunfailures 如果运行报错, 则使用python编辑器重新安装 1. 通过装饰器使用:@pytest 阅读全文
posted @ 2022-03-31 17:28 博无止境 阅读(165) 评论(0) 推荐(0) 编辑
摘要:# 定义列表 list1 = ["11", 5, 17, 18, 23] # 将列表的值转成int list1 = list(map(int, list1)) # 将列表内的值相加 print("列表元素之和为: ", sum(list1)) >>>列表元素之和为: 74 阅读全文
posted @ 2022-03-28 11:02 博无止境 阅读(351) 评论(0) 推荐(0) 编辑
摘要:方法一:通过关键字替换 # str.replace('旧字符串' , '新字符串' , '替换最大次数(可省略)') temp_str = '你好吗? 我很好' # 将所有i替换成aa print(temp_str.replace('好', '坏')) # 将i替换成aa,只替换一次 print(t 阅读全文
posted @ 2022-03-25 15:09 博无止境 阅读(28144) 评论(0) 推荐(0) 编辑
摘要:# type()的使用方法 a = "123" print(type(a)) >>><class 'str'> # isinstance()的使用方法: a = "123" print(isinstance(a, int)) print(isinstance(a, str)) >>> False T 阅读全文
posted @ 2022-03-21 15:15 博无止境 阅读(77) 评论(0) 推荐(0) 编辑
摘要:去掉字符串中不想要的逗号,括号等 n = '[123,456,789]' n = n.replace(',', '') # 去掉逗号 n = n.replace('[', '') # 去掉左括号 n = n.replace(']', '') # 去掉有括号 print(n)>>>123456789 阅读全文
posted @ 2022-03-17 19:13 博无止境 阅读(2846) 评论(0) 推荐(0) 编辑
摘要:1. “isdigit” 函数,判断字符串中是否全部为“数字”。 如果字符串中有一个不是数字, 则为False strs = "123" if strs.isdigit(): print("是数字") else: print("不是数字") 运行结果: >>>是数字 2. 判断字符串中是否包含“数字 阅读全文
posted @ 2022-03-09 18:29 博无止境 阅读(10886) 评论(0) 推荐(0) 编辑
摘要:# 将元组中的None值去掉,并转换为list input_= [('接口自动化测试用例', None, None, None, None, None, None)] output = [] for each in input_: newList = list(filter(None,each)) 阅读全文
posted @ 2022-03-09 17:40 博无止境 阅读(408) 评论(0) 推荐(0) 编辑
摘要:1. 启动手机模式浏览器, 手机型号只能选以下范围。 from selenium.webdriver.chrome.options import Options# 手机模式 # 设置手机型号,这设置为iPhone 6 mobile_emulation = {"deviceName": "iPhone 阅读全文
posted @ 2022-03-09 11:42 博无止境 阅读(2110) 评论(0) 推荐(0) 编辑
摘要:# 导入需要查看的模块 from browsermobproxy import server # 打印库文件位置 print(server.__file__) 阅读全文
posted @ 2022-02-17 10:05 博无止境 阅读(352) 评论(0) 推荐(0) 编辑
摘要:获取当前时间: localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) print(localtime) #打印: 2022-01-04 19:44:47 进程已结束,退出代码为 0 获取当前时间戳:如果想让小数点后移,则*1 阅读全文
posted @ 2022-01-04 19:48 博无止境 阅读(1907) 评论(0) 推荐(0) 编辑
摘要:如图乱码, 有两个原因: 原因一:没有配置pycharm变量。 解决方法:将pycharm的bin目录配置到path系统变量中。 原因二:没有配置allure变量。 解决方法:将allure的bin目录配置到path系统变量中。 阅读全文
posted @ 2021-12-07 10:21 博无止境 阅读(733) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示