随笔分类 - Python基础
摘要:用 __new__方法 #_*_ encoding: utf-8 _*_ @author: ty hery 2019/9/6 class Singleton(object): def __new__(cls): if not hasattr(cls,'_instance'): cls._instan
阅读全文
摘要:函数的列表作为默认参数带来的问题 #_*_ encoding: utf-8 _*_ @author: ty hery 2019/9/5 def extendList(val, list=[]): print('这个是开始之前列表: ',list) list.append(val) print(f'这
阅读全文
摘要:#_*_ encoding: utf-8 _*_ @author: ty hery 2019/9/6 def multipliers(): return [lambda x : i * x for i in range(4)] print ([m(2) for m in multipliers()]
阅读全文
摘要:##生成器版斐波那契 #_*_ encoding: utf-8 _*_ @author: ty hery 2019/9/5 def fibonacci(): a,b=0,1 while True: yield b a,b = b, a+b fib=fibonacci() print(type(fib
阅读全文
摘要:# 查出类的所有key值 cls.__table__.columns.keys() cls.__table__.columns.values() self.__class__.__name__ __get__方法详解: https://blog.csdn.net/qq_34979346/articl
阅读全文
摘要:#_*_ encoding: utf-8 _*_ @author: ty hery 2019/9/6 def table_things(**kwargs): for name, value in kwargs.items(): print ('{0} = {1}'.format(name, valu
阅读全文
摘要:#_*_ encoding: utf-8 _*_ @author: ty hery 2019/9/6 class Parent(object): x = 1 class Child1(Parent): pass class Child2(Parent): pass print (Parent.x,
阅读全文
摘要:此篇文章比较详细,写了些(?P\d+)等分组: https://www.cnblogs.com/zjltt/p/6955965.html https://www.cnblogs.com/shenjianping/p/11647473.html python-re模块 .,[],\d,\w,\s,\S
阅读全文
摘要:装饰器改变属性 def test1(): '''test1...''' print('test1') def test2(): '''test2...''' print('test2') print (test1.__name__) print (test1.__doc__) print (test
阅读全文
摘要:1.调用glob glob.blob遍历指定目录下的所有文件和文件夹,不递归遍历,需要手动完成递归遍历功能。 注意windows用'2个\'和linux用'/',以及最后的'*' import glob as gb path = gb.glob('E:\\前端帮助文档\\*') print(path
阅读全文
摘要:  : def __init__(self, r): self.r = r def area(self): return self.r **2* 3.14 #lib2.py class Triangle(object): def __
阅读全文
摘要:子问题重复计算问题: ,运行结果很慢 ! 解决方法:设置缓存,先从缓存中查找,没有再重新计算放入缓存, 运行结果很快就出了了, 计算结果: 20365011074 对于走楼梯问题同样也适用 优化方法:对于多个同样的问题,每次添加cache很麻烦,所以新增装饰器来保存cache,调用瞬间就计算出来了结
阅读全文
摘要:1. 协程 协程(Coroutine),也可以被称为微线程,是一种用户态内的上下文切换技术。简而言之,其实就是通过一个线程实现代码块相互切换执行。 在Python中有多种方式可以实现协程,例如: greenlet,是一个第三方模块,用于实现协程代码(Gevent协程就是基于greenlet实现) y
阅读全文
摘要:深浅拷贝 Counter filter 过滤 列表排序 闭包
阅读全文
摘要:1, 连接pymysql ,批量处理 # _*_ encoding:utf-8 _*_ import pymysql # 连接数据库 conn = pymysql.connect(host='10.21.252.61', port=13306, user='root', password='root
阅读全文
摘要:1. 生成列表的费时对比 #_*_coding:utf-8_*_ from timeit import Timer def test1(): li =[] for i in range(10000): li.append(i) def test2(): li = [] for i in range(
阅读全文
摘要:3.1事件循环 理解成为一个死循环,去检测并执行某些代码。 仿代码 任务列表-【任务1。任务2。任务3.] while True: 可执行的任务列表,已完成的任务列表 = 去任务列表中检查所有的任务,将"可执行" 和 "已完成"的任务返回 for就绪任务 in可执行的任务列表: 执行已就堵旳任务 f
阅读全文
摘要:class Player(object): def __init__(self, uid, name, status=0, level=1): self.uid = uid self.name = name self.stat = status self.level = level class Pl
阅读全文

浙公网安备 33010602011771号