python优化
sky0Lan
打杂的
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python logging QueueHandler使用
减少日志打印过程种,多程序处理造成的处理速度慢的场景。原创 2022-08-26 16:37:45 · 2427 阅读 · 0 评论 -
python concurrent.futures
from time import timedef gcd(pair): a, b = pair low = min(a, b) for i in range(low, 0, -1): if a % i == 0 and b % i == 0: return iif __name__ == '__main__': numbers = [(1963309, 2265973), (2030677, 3814172), (15516原创 2021-10-29 10:43:33 · 158 阅读 · 0 评论 -
* python Mix-in类,制作工具组件
Mix-in 类一种小型的类,它只定义其它类可能需要提供的一套附加方法,而不定义自己的类实例属性。此外,它也不要求使用者调用自己的 __init__ 构造器。(避免多继承问题)class ToDictMixin: """ 把内存中的 python 对象转换为字典形式,以便将其序列化。 """ def to_dict(self): return self._traverse_dict(self.__dict__) def _traver原创 2021-09-27 20:19:27 · 205 阅读 · 0 评论 -
** python 使用@classmethod形式的多态去通用地构建对象
统计输入中的换行符import osfrom threading import Threadclass InputData: def read(self): raise NotImplementedErrorclass PathInputData(InputData): def __init__(self, path): super().__init__() self.path = path def read(self原创 2021-09-17 15:30:41 · 208 阅读 · 0 评论 -
** python 挂钩函数
挂钩函数在 sort 中的使用1根据挂钩函数的返回值进行排序names = ['Socrates', 'Archimedes', 'Plato', 'Aristotle']names.sort(key=lambda x: len(x))print(names)输出['Plato', 'Socrates', 'Aristotle', 'Archimedes']挂钩函数在 defaultdict 中的使用2字典 current 没有 increments 中的键时候,打印日志信息fro原创 2021-09-14 20:27:00 · 254 阅读 · 2 评论 -
python 扩展print 方法
# encoding=UTF-8p = printdef sp_print(*args, **kwargs): p('args', args) p('kwargs', kwargs) p(*args, **kwargs)print = sp_printprint('aaa')原创 2021-06-04 19:02:06 · 215 阅读 · 0 评论 -
python 字符串链接 + 与 join 效率问题
# encoding=UTF-8""" 去除字符串中的非字母字符(即生成仅包含原字符串中字母的字符串)"""# WARNING: do not do thisdef retain_aplpha_01(document): letters = '' # start with empty string for c in document: # type: str if c.isalpha():原创 2021-06-16 20:10:33 · 244 阅读 · 0 评论
分享