Python
文章平均质量分 50
Mi5tAke
这个作者很懒,什么都没留下…
展开
-
Python 中 collections模块使用
collections是Python内建的一个集合模块,提供了许多有用的集合类。namedtuple我们知道tuple可以表示不变集合,例如,一个点的二维坐标就可以表示成:>>> p = (1, 2)但是,看到(1, 2),很难看出这个tuple是用来表示一个坐标的。定义一个class又小题大做了,这时,namedtuple就派上了用场:>>> from collections import namedtuple>>> P转载 2021-03-26 13:22:10 · 145 阅读 · 0 评论 -
Python 中 typing 模块和类型注解的使用
源:https://cuiqingcai.com/7071.html实例引入我们知道 Python 是一种动态语言,在声明一个变量时我们不需要显式地声明它的类型,例如下面的例子: 12 a = 2print('1 + a =', 1 + a) 运行结果: 1 1 + a = 3 这里我们首先声明了一个变量a,并将其赋值为了 2,然后将最后的结果打印出来,程序输出来了正确的结果。但在这个过.转载 2021-03-22 14:15:46 · 2071 阅读 · 0 评论 -
Python字典转对象定义
新类重新赋值转化法先建一个新类 Dict :class Dict(dict): __setattr__ = dict.__setitem__ __getattr__ = dict.__getitem__该类集成了原字典 dict 类,字典不能使用点调用属性,而该类可以,于是我们做值的转换:def dictToObj(dictObj): if not isinstance(dictObj, dict): return dictObj d = D...原创 2021-03-10 13:48:34 · 402 阅读 · 0 评论 -
接口返回二进制ProtoBuf流反解析
import subprocessdef pbdecode(data): process = subprocess.Popen(['./protobuf/protoc.exe', '--decode_raw'], stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE) output = error = None try: output, error = process.c.原创 2021-03-10 13:45:29 · 766 阅读 · 0 评论 -
python-Mitmproxy抓包
一、使用安装pip install mitmproxymitmproxy 是具有控制台界面的交互式,支持SSL的拦截代理mitmdump是mitmproxy的命令行版本。想想tcpdump为HTTPmitmweb 是一个基于web的界面,适用于mitmproxymitmproxy(mac)、mitmdump、mitmweb(win) 这三个命令中的任意一个即可mitmweb -s mitm.py 命令行启动默认端口8080mitmweb -p 8888 -s mitm.py 指定端口888原创 2021-03-10 11:30:16 · 696 阅读 · 0 评论 -
VSCode配置项目launch.json文件
{//UseIntelliSensetolearnaboutpossibleattributes.//Hovertoviewdescriptionsofexistingattributes.//Formoreinformation,visit:https://go.microsoft.com/fwlink/?linkid=830387"version":"0.2.0","configurations":[...原创 2020-12-20 19:31:23 · 4235 阅读 · 0 评论 -
Python标准模块--logging的使用总结
1 logging模块简介logging模块是Python内置的标准模块,主要用于输出运行日志,可以设置输出日志的等级、日志保存路径、日志文件回滚等;相比print,具备如下优点:可以通过设置不同的日志等级,在release版本中只输出重要信息,而不必显示大量的调试信息; print将所有信息都输出到标准输出中,严重影响开发者从标准输出中查看其它数据;logging则可以由开发者决定将信息输出到什么地方,以及怎么输出;2 logging模块使用2.1 基本使用配置logging基本的设置转载 2020-11-23 16:27:00 · 260 阅读 · 0 评论 -
Python打印彩色文字
#!/usr/bin/python# -*- coding: UTF-8 -*-import ctypesdef echo(*o,c=7,sep=' ',end='\n'):k=ctypes.WinDLL("Kernel32.dll");h=k.GetStdHandle(-11);f=k.SetConsoleTextAttribute;f(h,c);print(*o,sep=sep,end=end,flush=True);f(h,7)'''-参数c 高8位:...转载 2020-09-07 09:19:10 · 275 阅读 · 0 评论