python 很久以前的笔记保存
批量替换请求头 (.*?):(.*) '$1':'$2', # 用法 #*kwargs demo(a=(Exception, RequestHandler), name={"age": "12"}) demo(**kwargs): #结果为 a name print(*kwargs) #调用父类方式 def _handle_request_exception(self, e: BaseException) -> None: super(RequestHandler, self)._handle_request_exception(e) #prefix 前缀 # class Demo(object): def __init__(self): self._a = None self._x = None @property def a(self): return self._a @a.setter def a(self, value): self._a = value def setx(self, value): self._x = value def getx(self): return self._x x = property(fset=setx, fget=getx, doc='this is x') property(set_func,get_func,...) from functools import wraps @wraps() #保证传递进来的函数名字及__name__ 为自身方法名 import traceback try: c = 1 / 0 except Exception as e: #将异常以字符串形式打印出来 print(traceback.format_exc()) #线程池 import time from concurrent.futures import ThreadPoolExecutor def ceshi(times): time.sleep(times) print(f"等{times}秒") return times executor = ThreadPoolExecutor(max_workers=10) task1 = executor.submit(ceshi, (2,)) task2 = executor.submit(ceshi, (3,)) task3 = executor.submit(ceshi, (1,)) # 执行顺序 warps(前0.5) ----> wraps01(前0.5)----->demo----->wraps01(后0.5)-------->warps(后0.5) !!!!!! def wraps(name): print('----A-----') def wraps01(*args, **kwargs): print('----A1-----') name(*args, **kwargs) print('----A2-----') return wraps01 def wraps_a(name): print('----B-----') def wraps_b(*args, **kwargs): print('----B1-----') name(*args, **kwargs) print('----B2-----') return wraps_b @wraps @wraps_a def demo(): print('1234') demo() """ ----B----- ----A----- ----A1----- ----B1----- 1234 ----B2----- ----A2----- """