随笔分类 -  python知识

python coverage 代码覆盖率
摘要:coverage run main.py coverage report coverage html -d resulthtml 自动生成 # 使用 API 生成代码覆盖率统计报告# exec_api.py import coverageimport unittest # 实例化一个对象cov = 阅读全文

posted @ 2022-10-28 19:08 HHMLXL 阅读(51) 评论(0) 推荐(0) 编辑

pandas
摘要:import numpy as np import pandas as pd def main(): # 创建 # Serier 仅有index轴,DataFrame index与columns 行与列 index = pd.date_range('1/1/2022', periods=8) a = 阅读全文

posted @ 2022-07-08 14:25 HHMLXL 阅读(18) 评论(0) 推荐(0) 编辑

numpy
摘要:import sys import numpy as np import pandas as pd def main(): np.set_printoptions(threshold=sys.maxsize) # 数组太大无法打印,会跳过中心部分打印角点,禁用此行为打印全部 # 创建 print(n 阅读全文

posted @ 2022-07-06 15:35 HHMLXL 阅读(12) 评论(0) 推荐(0) 编辑

编码 中文转unicode
摘要:print("未知功能".encode('unicode-escape').decode()) 阅读全文

posted @ 2022-01-24 11:28 HHMLXL 阅读(30) 评论(0) 推荐(0) 编辑

python 编译反编译
摘要:def test(): print(1+1) if __name__ == '__main__': test() ''' pip install uncompyle6 编译 python -m py_compile test.py 生成test.pyc文件 反编译 uncompyle6 test.p 阅读全文

posted @ 2021-12-20 14:53 HHMLXL 阅读(198) 评论(0) 推荐(0) 编辑

python 代码逐行耗时分析
摘要:@profile def test(): print(1+1) if __name__ == '__main__': test() ''' pip install line_profiler kernprof -l -v test.py -l 逐行分析 -v 输出 Wrote profile res 阅读全文

posted @ 2021-12-20 14:43 HHMLXL 阅读(160) 评论(0) 推荐(0) 编辑

子序列和最大
摘要:def demo(nums): dp=[nums[0]] for i in nums[1:]: dp.append(max(i,dp[-1]+i)) return max(dp) print(demo([-2,1,-3,4,-1,2,1,-5,4])) 阅读全文

posted @ 2021-06-23 09:41 HHMLXL 阅读(32) 评论(0) 推荐(0) 编辑

python grpc
摘要:grpc 远程过程调用 优势:采用protobuf二进制消息,效率高;序列化后消息体积小;节省网络流量;序列化和反序列化直接对应程序中数据类;劣势:protobuf二进制可读性差 使用protobuf数据传输,protobuf是一种数据交换格式,由三部分构成proto 文件 :使用的proto语法的 阅读全文

posted @ 2021-06-22 15:30 HHMLXL 阅读(216) 评论(0) 推荐(0) 编辑

python 单例模式
摘要:# __new__ class Demo: def __new__(cls, *args, **kwargs): if not hasattr(cls,'_instance'): cls._instance=super().__new__(cls) return cls._instance a=De 阅读全文

posted @ 2021-06-17 15:31 HHMLXL 阅读(35) 评论(0) 推荐(0) 编辑

python多进程
摘要:from multiprocessing import Pool import os #进程池批量创建子进程 def task(args): #执行任务 print(args) if __name__ == '__main__': # cpu处理器-1 pool_num=os.cpu_count() 阅读全文

posted @ 2021-05-07 09:40 HHMLXL 阅读(36) 评论(0) 推荐(0) 编辑

Python nonlocal global用法
摘要:# 在基本的python语法当中,一个函数可以随意读取全局数据,但是要修改全局数据的时候有两种方法:# # 1 global 声明全局变量 2 全局变量是可变类型数据的时候可以修改# 在python3中,可以用nonlocal 关键字声明 一个变量, 表示这个变量不是局部变量空间的变量,需要向上一层 阅读全文

posted @ 2020-10-15 09:50 HHMLXL 阅读(120) 评论(0) 推荐(0) 编辑

Python filter、map、eval内置函数
摘要:# filter() 函数用于过滤序列,过滤掉不符合条件的元素,返回由符合条件元素组成的新列表。 # 该接收两个参数,第一个为函数,第二个为序列,序列的每个元素作为参数传递给函数进行判断,然后返回 True 或 False,最后将返回 True 的元素放到新列表中。 def test(n): ret 阅读全文

posted @ 2020-10-13 15:23 HHMLXL 阅读(165) 评论(0) 推荐(0) 编辑

Python 二、八、十、十六进制转换
摘要:Python 二、八、十、十六进制转换 阅读全文

posted @ 2020-10-09 11:00 HHMLXL 阅读(258) 评论(0) 推荐(0) 编辑

Python re模块
摘要:Python re模块 阅读全文

posted @ 2020-09-17 16:29 HHMLXL 阅读(108) 评论(0) 推荐(0) 编辑

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