随笔分类 - python
摘要:目录操作需要用到os模块 import osimport timeimport datetime# 获取当前时间戳 20240101100101格式current_run = datetime.datetime.now().strftime("%Y%m%d%H%M%S")print(datetime
阅读全文
摘要:"""@Name: config.py@Author: zengchuanyin@Date 2023/9/14-0:2 0"""import osimport yamlproject_path = os.path.split(os.path.abspath(__file__))PRO_DIR = p
阅读全文
摘要:"""@Name: data_conf.py@Author: zengchuanyin@Date 2023/6/11-16:19"""import yamlconf_path = "conf_env.yml"def get_data_from_yml(): with open('conf_env.y
阅读全文
摘要:"""@Name: test_django_service_01.py@Author: zengchuanyin@Date 2024/2/25-10:56"""import pytestimport loggingimport jsonfrom config import get_env_msgfr
阅读全文
摘要:class ServiceBase(object): def __init__(self, host, vpath, headers: dict = None): self.host = host self.vpath = vpath self.headers = headers def befor
阅读全文
摘要:假设父类: class Parent(object): def __init__(self): print("打印父类") print(__class__) self.p_name = "父类属性" self.p_code = "10000" def get_parent_function(self
阅读全文
摘要:1.数据库信息yaml文件 conf_env.yaml host: doname: demo.pab.com.cn port : 80database: host: "db.fat.qa.pab.com.cn" user: "deploy" password: "thess" dbname: "te
阅读全文
摘要:用python对接口进行测试时,如果接口要求的参数是json串格式,那么在python中,需要用json.dumps()方法将字典转换为json字符串; 如果接口响应结果是json字符串,在需要做断言处理时,用json.loads()方法将json字符串转换为字典 #需要用到json模块 impor
阅读全文
摘要:修改列表的元素时,可以使用for 循环结合range n = int(input()) list_b = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] for i in range(len(list_b)): for y in range(len(list_b[i])): li
阅读全文
摘要:num_list = []for i in range(1,16): if i == 13: continue else: num_list.append(str(i))str_num = ' '.join(num_list)
阅读全文
摘要:list_a = [1, 2, 3] list_d = [i for i in list_a]#[1, 2, 3] list_e = [i*j for i in list_a for j in list_c]#[4,5,6,10,12,12,15,18] list_f = [i*j for i,j
阅读全文
摘要:python中保留n位小数,可以使用round 函数 a = 34.564636856845754print(round(a, 2))print(round(a, 3))
阅读全文
摘要:from django.test import TestCase# Create your tests here.class A: def __init__(self): self.a = "a" print("A")class B: def __init__(self): self.b = "b"
阅读全文
摘要:num_list = [1,2,3,4] num_list[0],num_list[2] = num_list[2],num_list[0]num_list[1],num_list[3] = num_list[3],num_list[1] print(num_list)
阅读全文
摘要:import xlrdimport xlwt"""获取文件对象"""data = xlrd.open_workbook('pyt.xls')#通过index获取第一个sheet"""读文件,获取sheet对象"""table = data.sheets()[0]#获取所有sheettable_nam
阅读全文
摘要:如建立conf_fat.yml文件,内容: host: doname: demo.pab.com.cn port : 80 创建py_yaml.py文件,内容: import yamlwith open("conf_fat.yml", "r") as file: content = file.rea
阅读全文
摘要:例如给定一个列表a,用冒泡排序法,将a里面的元素从小到大进行排序 实现思想: 1.确定列表表长(元素个数),用于确定最多循环次数,为len(list)长度 2.确定列表内第一次循环,第一个元素的最多比较次数,为len(list) -1 - i,i为循环次数变量 3.设置排序标记位,sort_sign
阅读全文
摘要:class GenerateFile: def __init__(self,file_size): #file_size 定义文件大小 self.file_size = str(file_size) self.file_path="G:\zeng\Videos\\" self.file_name="
阅读全文
摘要:json.load:表示读取文件,返回python对象json.dump:表示写入文件,文件为json字符串格式,无返回 json.dumps:将python中的字典类型转换为字符串类型,返回json字符串 [dict→str]json.loads:将json字符串转换为字典类型,返回python对
阅读全文
摘要:需要用到itertools.combinations方法 m也可以是list,tuple,dict等对象from itertools import combinationsm =['1', '2', '3', '4', '5', '6', '7']c = 0n=6for i in list(comb
阅读全文

浙公网安备 33010602011771号