python
菽绣
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
简单进度条
import timeimport sysclass Tqdm: def __init__(self, obj): self.obj = obj self.total = len(obj) self.gran = 20 def __iter__(self): now = 0 for i in self.obj: yield i now += 1原创 2021-10-11 16:37:38 · 176 阅读 · 0 评论 -
bottle源码分析——深入理解web开发
wsgi的实现web服务器程序实现wsgi协议这是python标准库里的web服务器的实现方式,从tcp包中解析出http请求的相关字段存入environ,然后传给web应用程序application,最后返回web应用程序的处理结果def run(self, application): self.setup_environ() result = application(self.environ, self.start_response) return原创 2021-10-09 18:11:23 · 620 阅读 · 0 评论 -
python列表各方法性能情况
从测验结果可以看出,python列表的底层数据结构为数组append:O1insert尾部:接近O1,慢于appendinsert头部:Onpop:O1pop头部:On__setitem__:O1__getitem__:O1contain:On测验代码:def cat_runtime(f): def wrap(*args, **kwargs): st = time.time() f(*args, **kwargs) print(f'{f.__name__}: {time.t原创 2020-12-05 11:30:47 · 241 阅读 · 0 评论 -
python 动态编程 字符串转变量 字符串转对象
python 动态编程 元编程 字符串转变量 字符串转对象字符串转对象可能会遇到这样一个场景:存储常量的配置文件通常是不从外部模块导入变量或对象的,否则很可能出现交叉导入的错误,那么要在配置文件里存储一个外部模块中的对象的话,只能用字符串存储,像这样:printers.pyclass Print1: def __init__(self): print('i am Print1')class Print2: def __init__(self): prin原创 2020-11-26 15:31:40 · 636 阅读 · 0 评论 -
编写高质量Python代码的59个有效方法 第20条:用None来描述具有动态默认参数
先上代码:import datetime, timedef log(message, when=datetime.datetime.now()): print(message, when)log('hello once')time.sleep(2)log('hello twice')>>>hello once 2018-09-19 20:47:35.700...原创 2018-09-20 14:37:50 · 165 阅读 · 0 评论
分享