共 62 篇文章 |
|
阅42 转1 评0 公众公开 18-12-26 09:42 |
阅32 转3 评0 公众公开 18-12-21 10:30 |
进程池和线程池、协程。ThreadPool(2)#创建线程池 #p=Process()创建进程池 #p.apply(func,args.kwargs) 执行进程 #p.close() p.jion() requests = threadpool.makeRequests(sayhello,seed)#创建任务 makeRequests(func,args,kwargs) for request in requests: task_pool.putRequest(request)#把任务put到线程池中 task_pool.wait()#执行等待线... 阅207 转0 评0 公众公开 18-12-18 16:15 |
python 进度条for i in range(100):print(">",end="",flush = True) #flush默认为False ,设置成True 实时打印缓存信息for i in range(10):print("\r"+"<" * i,end = "") #\r默认将指针返回到最开始后输出(在原位置再次输出) 阅26 转0 评0 公众公开 18-12-13 15:26 |
阅78 转1 评0 公众公开 18-12-11 15:36 |
#match 从要被匹配的字符串开头开始匹配, 如果没有匹配到返回Nonea = re.match("c","abc")#search 在被匹配的字符串中寻找匹配,如果使用^就等价于matcha = re.search("c","abc").group()a = re.search("^c","abc")#返回一个正则表达式对象pattern = re.compile("A").... 阅47 转0 评0 公众公开 18-12-10 15:50 |
python---类装饰器和函数装饰器函数装饰器如下: 类装饰器写法:__init__:初始化类__call__:给实例对象赋予函数执行的功能。 阅893 转0 评0 公众公开 18-12-05 17:36 |
阅39 转0 评0 公众公开 18-12-05 10:43 |
python global、locals()、nonlocalglobal 定义全局变量,必须先声明,在使用例如:global a #声明全局变量 a = a+1locals() 获取本函数作用域中的局部变量(函数即变量)nonlocal 必须在整个嵌套函数作用域内定义局部变量,获取上层函数的变量例如:1.def test():a = 1def test1():nonlocal a #必须先声明a = a+1print (a)return test1t = ... 阅143 转0 评0 公众公开 18-12-04 09:42 |
python 静态属性、静态方法、静态类。#静态属性 @property #定制静态属性方法,跟实例绑定,让用户感知不到后端的运行逻辑 def room(this): return this.w*this.l.#类方法 @classmethod #类方法:跟类绑定,和实例没有任何关系,只是类级别的操作时用,实例也可以调用 def tell_info(cls): print(cls) print(cls.x)#静态方法 @staticmethod #静... 阅2787 转1 评0 公众公开 18-12-03 16:20 |