
python
词穷墨尽
don't try so hard the best things come when you least expect them to
不定时更新~~
展开
-
os.path.dirname
#!/usr/bin/env python# -*- coding:utf-8 -*-# Author:victor Liimport osfrom enum import Enumclass DirInfo(Enum): p=os.path.abspath(__file__) root_dir=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# os.path.dirname返回当前目录的上层目录 .原创 2022-04-18 15:20:58 · 721 阅读 · 0 评论 -
python 格式化日期输出
import timedef get_time_to_str(str_format='%Y-%m-%d %H:%M:%S'): res = time.strftime(str_format, time.localtime(time.time())) return resdef get_date_as_name(): return get_time_to_str('%Y-%m-%d')原创 2020-12-15 13:24:21 · 1060 阅读 · 0 评论 -
关于目录的 枚举化管理
# -*- coding:utf-8 _*-""" @author:victor@time: 2018/12/17 @email:2213097666@qq.com@function: 常量"""import osfrom enum import Enumclass DirINfo(Enum): base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # 项目根路径 case_d.原创 2020-12-07 11:34:30 · 140 阅读 · 0 评论 -
locust 通过队列实现 task级集合点并发
最近公司在搞压测 笔者也是查了很多工具lr收费 用不起 jm 测试机扛不住 最后就选择了locust使用中有个场景覆盖不到 就是几个task中 有一个需要并发提交,其余task正常运行即可也是查了一些资料官网上给的钩子方法 是基于协程的运行开始前可实现并发一旦运行开始即开始即不可控#!/usr/bin/env python# -*- coding:utf-8 -*-# Author:victor Li#任务类import queuefrom locust import ..原创 2020-05-27 01:33:45 · 1168 阅读 · 4 评论 -
unittest实现加载多个class对象运行
#网上查了写资料发现没有通过list[class]方式去加载用例#然后去看了下源码发现loadTestsFromNames一个suite可以返回多个数据所以就修改了下调用方法 把#loadTestsFromName改成了loadTestsFromTestCase...原创 2020-03-17 17:23:21 · 526 阅读 · 0 评论 -
python import_module导入方法
#!/usr/bin/python# -*- coding: UTF-8 -*-# @Time :2020/3/16 16:44# @Author : victorimport importlibimport typesdef is_function(tup): """ Takes (name, object) tuple, returns True if it...原创 2020-03-16 17:03:26 · 1160 阅读 · 0 评论 -
python 实现装饰器带参数
import time def timer(function): # 装饰器接收被装饰的函数 def wrapper(): start_ti = time.time() result = function() # 调用被装饰的函数 end_ti = time.time() total_ti = end_ti - ...原创 2020-03-16 15:05:28 · 316 阅读 · 0 评论 -
python post请求 url携带参数提交后409 或url参数加密处理问题
from urllib.parse import quote, unquote """post请求""" def __init__(self,logger): self.logger=logger def request_by_post(self, session, url, param): self.logger_info(url,par...原创 2019-09-04 13:43:41 · 1389 阅读 · 0 评论 -
python 设置日志级别输出渠道/设置日志输出格式
# 日志级别 debug info waring error critical#从左 往右越来越严重#root logger 收集日志的容器 如果你不定义一个logger 那么就默认使用root logger#输出渠道 handlers 渠道 控制台console 文本:file_handler 渠道默认是控制台#pre-defined format 按照提前设置好的格式进行...原创 2019-08-27 22:06:23 · 1540 阅读 · 0 评论 -
python excel 数据驱动
from openpyxl import load_workbookimport openpyxl.workbookimport osclass Case: def __init__(self): self.case_id=None self.request_type = None self.url = None se...原创 2019-08-27 11:02:19 · 697 阅读 · 0 评论 -
python 读取配置文件
import configparserimport osclass ReadConfig: def __init__(self): self.config=configparser.ConfigParser() def read_config(self,section,key): path = os.path.split(os.path.real...原创 2019-08-27 10:56:49 · 236 阅读 · 0 评论 -
跟着词穷学python之文件流自动关闭
# file =open("test13.txt","w+",encoding="UTF-8")# file.write("如懿传")#文件是否关闭# print(file.closed)# file.close();# print(file.closed)""" `with....as..... 上下文管理器"""with open("test13.txt","w+"...原创 2020-03-16 15:06:32 · 290 阅读 · 0 评论 -
跟着词穷 学python之函数的概念
""""""#调用函数: 函数名(对应个数的参数)#return 的作用就是当你调用函数的时候 会返回return 后面表达式的值# def radio_machine():# print("我就是个复读机 只会说你好")# return# def radio_machine():# print("我就是个复读机 只会说你好")# # ...原创 2019-07-31 14:53:31 · 137 阅读 · 0 评论 -
跟着词穷学python之函数的参数类型
#1、 函数的参数个数可以大于等于0#2、为什么要添加参数?# 还是要提高代码的复用性,参数是通过函数参数列表传递进来def count_number(m,n): count=0; for i in range(m,n): count+=i; print("count={}".format(count)) #如果函数没有写r...原创 2019-07-31 14:56:37 · 124 阅读 · 0 评论 -
跟着词穷学python之函数的调用 (函数顺序很重要)
def student_info(class_name, name, offer): print("{}的{}同学拿到了{}k的offer".format(class_name, name, offer)) eat("煎饼", '小鱼干', '火锅', "泡面", "玉米")# eat("煎饼", '小鱼干', '火锅', "泡面", "玉米") 和java pyt...原创 2019-07-31 15:45:38 · 243 阅读 · 0 评论 -
跟着词穷学python之python的全局变量与局部变量
#python 里面的全局变量和局部变量#函数内部的是局部变量#函数外部的是全局变量# offer=20#全局变量# def student_info(class_name, name):# offer=100#局部变量 在函数内取值时 局部变量的优先级高于全局变量# print("{}的{}同学拿到了{}k的offer".format(class_name, na...原创 2019-07-31 16:44:32 · 175 阅读 · 0 评论 -
python 判断对象是否可迭代
from collections.abc import IterableP=[[1,2,3],[4,5,6],[7,8,9]]print(isinstance(P,Iterable))#true;原创 2019-07-22 21:57:54 · 286 阅读 · 0 评论 -
python range函数
#range函数 生成一个整数序列 可迭代对象#range(m,n,k) m开头的数字 n结尾的数字 k 是步长 默认为1 左闭右开#如果range(m,n) k默认为1#如果range(n) m默认为0# res=range(1,10);# print(set(res))res=range(10);print(res)#如果我要生成0~100的数字for i in ra...原创 2019-07-22 22:44:01 · 308 阅读 · 0 评论 -
使用seek()方法报错:“io.UnsupportedOperation: can't do nonzero cur-relative seeks”错误的原因
在使用seek()函数时,有时候会报错为“io.UnsupportedOperation: can't do nonzero cur-relative seeks”,代码如下:file = open("python13.txt", "w+", encoding="utf-8")file.write("那年我们逝去的青春")file.seek(3,1)#重新改变光标的位置 移动的量,相...原创 2019-08-01 10:16:40 · 912 阅读 · 1 评论 -
python之OS处理
#绝对路径 相对路径#包含根目录的路径是绝对路径 D:\mypython\week_3# f1=open("python13.txt",encoding="UTF-8");#相对路径# print(f1.read())# f2=open("D:\mypython\week_3\class_12_15\python13.txt",encoding="UTF-8")#絕對路徑# pri...原创 2019-08-06 15:06:31 · 146 阅读 · 0 评论 -
跟着词穷学python之file文件处理
# 文件打开的模式 open 函数默认的模式 是r# r 只读 r+ 读写# file=open("python13.txt","r+",encoding="utf-8")# print(file.readline())# file.write("123123")#如果不设置模式 会抛异常io.UnsupportedOperation: not writable# w 只写...原创 2019-08-06 15:08:16 · 155 阅读 · 0 评论 -
python 判断 对象是否可迭代
from collections.abc import Iterable #3.8后不能用from collections. import Iterable result=isinstance("abc",Iterable);#Trueprint(result)result=isinstance(1,Iterable);#Falseprint(result)原创 2019-07-09 17:15:51 · 192 阅读 · 0 评论