02 2017 档案
摘要:1 import threading 2 import time 3 def f0(): 4 pass 5 def f1(a1,a2): 6 time.sleep(10) 7 f0() 8 print("1") 9 10 t1 = threading.Thread(target=f1,args=(111,123)) 11 # t.setDaem...
阅读全文
摘要:1 from multiprocessing import Process,Pool 2 import time 3 #进程池的使用 4 def Foo(i): 5 time.sleep(2) 6 return i+100 7 def Bar(arg): 8 print (arg) 9 10 #print pool.apply(Foo,(1,)) 11...
阅读全文
摘要:1 import threading 2 import time 3 globals_num = 0 4 lock = threading.RLock() 5 def func(): 6 lock.acquire()#获得锁 7 global globals_num 8 globals_num += 1 9 time.sleep(1) 10 ...
阅读全文
摘要:1 #!/usr/bin/env python 2 import threading 3 # event.wait()##阻断线程向下执行 event_obj.set()#释放进程向下执行 4 def do(event): 5 print('start') 6 event.wait()##阻断线程向下执行 7 print('execute') 8 9 ...
阅读全文
摘要:1 #!/usr/bin/env python 2 import multiprocessing 3 import time 4 def f1(a1): 5 time.sleep(2) 6 print(a1) 7 if __name__ == '__main__': 8 t = multiprocessing.Process(target=f1,args=...
阅读全文
摘要:1 #!/usr/bin/env python 2 from multiprocessing import Process 3 4 li = [] 5 def f1(a1): 6 li.append(a1) 7 print(li) 8 if __name__ == '__main__': 9 for i in range(10): 10 ...
阅读全文
摘要:1 #!/usr/bin/env python 2 from multiprocessing import Process,Manager 3 4 #Manager进程与进程之间通信 5 def Foo(i,dic): 6 dic[i] = 100+i 7 print(dic.values()) 8 if __name__ == '__main__': 9 ...
阅读全文
摘要:1 import queue 2 import threading 3 4 5 class ThreadPool(object): 6 7 def __init__(self, max_num=20): 8 self.queue = queue.Queue(max_num) 9 for i in range(max_num): 10...
阅读全文
摘要:1 import queue 2 import contextlib 3 import time 4 @contextlib.contextmanager 5 def worker_state(xxx,val): 6 xxx.append(val) 7 print("before",xxx) 8 try: 9 time.sleep(1) ...
阅读全文
摘要:1 import queue 2 import threading 3 import contextlib 4 import time 5 6 StopEvent = object() 7 8 9 class ThreadPool(object): 10 11 def __init__(self, max_num): 12 13 ...
阅读全文
摘要:其他相关 一、isinstance(obj, cls) 检查是否obj是否是类 cls 的对象 二、issubclass(sub, super) 检查sub类是否是 super 类的派生类 1 class Foo(object): 2 pass 3 4 class Bar(Foo): 5 pass
阅读全文
摘要:《Python 面向对象(初级篇)》文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使用(可以讲多函数中公用的变量封装到对象中) 对象,根据模板创建的实例(即:对象),实例用于调用被包装在类中的函数 面向
阅读全文
摘要:
阅读全文
摘要:1 import queue 2 import contextlib 3 import time 4 5 6 @contextlib.contextmanager 7 def worker_state(xxx,val): 8 xxx.append(val) 9 print("before",xxx) 10 try: 11 time.s...
阅读全文
摘要:import Queue myqueue = Queue.Queue(maxsize = 10) Queue.Queue类即是一个队列的同步实现。队列长度可为无限或者有限。可通过Queue的构造函数的可选参数maxsize来设定队列长度。如果maxsize小于1就表示队列长度无限。 将一个值放入队列
阅读全文
摘要:模块,用一砣代码实现了某个功能的代码集合。 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合。而对于一个复杂的功能来,可能需要多个函数才能完成(函数又可以在不同的.py文件中),n个 .py 文件组成的代码集合就称为模块。 如:os 是
阅读全文
posted @ 2017-02-21 19:14
失落的黎明
摘要:#!/usr/bin/env python import hashlib def md5(arg): ooo = hashlib.md5(bytes('taochen', encoding='utf-8')) ooo.update(bytes(arg, encoding='utf-8')) retu
阅读全文
摘要:用于序列化的两个模块 json,用于字符串 和 python数据类型间进行转换 pickle,用于python特有的类型 和 python的数据类型间进行转换 Json模块提供了四个功能:dumps、dump、loads、load pickle模块提供了四个功能:dumps、dump、loads、l
阅读全文
摘要:时间相关的操作,时间有三种表示方式: 时间戳 1970年1月1日之后的秒,即:time.time() 格式化的字符串 2014-11-11 11:11, 即:time.strftime('%Y-%m-%d') 结构化时间 元组包含了:年、日、星期等... time.struct_time 即:tim
阅读全文
摘要:Python的字符串格式化有两种方式: 百分号方式、format方式。 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存。 1、百分号方式 %[(name)][flags][width].[precision]typecode (name) 可选,用
阅读全文
摘要:os.path.dirname返回上一级目录相当于os.path.split(path) 结果: os.path.exists(path)如果path存在,返回True;如果path不存在,返回False os.stat('path/filename')获取文件/目录信息
阅读全文
摘要:1 import sys 2 sys.path.append("D:") 3 for i in sys.path: 4 print(i)
阅读全文
摘要:python中re模块提供了正则表达式相关操作 字符: . 匹配除换行符以外的任意字符 \w 匹配字母或数字或下划线或汉字 \s 匹配任意的空白符 \d 匹配数字 \b 匹配单词的开始或结束 ^ 匹配字符串的开始 $ 匹配字符串的结束 次数: * 重复零次或更多次 + 重复一次或更多次 ? 重复零次
阅读全文
摘要:用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法
阅读全文
摘要:提供对操作系统进行调用的接口
阅读全文
摘要:用于提供对Python解释器相关的操作: 进度条百分比
阅读全文
摘要:1 #!/usr/bin/env python 2 import re 3 def f1(arg): 4 5 return 1 6 7 origin = "1 - 2 * ( ( 60 - 30 + ( -40.0 / 5 ) * ( 9 - 2 * 5 / 3 + 7 / 3 * 99 / 4 * 2998 + 10 * 568 / 14 )) - ( - 4 * 3...
阅读全文
摘要:1 #!/usr/bin/env python 2 import re 3 r = "aasa da.5a5dfgfda ada" 4 ret = re.findall('a',r) 5 print(ret)#1.查找全部a 6 ret = re.findall('^a',r) 7 print(ret)# 2.^ 查找开头 8 ret = re.findall('a$',r) ...
阅读全文
摘要:结果C:\Python35\python3.exe F:/Python/笔记1/a1.py3['asa', 'a']akda Process finished with exit code 0
阅读全文
摘要:1 #!/usr/bin/env python 2 r = round(3.6) 3 #四舍五入 4 print(r) C:\Python35\python3.exe F:/Python/2day/c7.py 4 Process finished with exit code 0
阅读全文
摘要:1 #!/usr/bin/env python 2 i = pow(2,5) 3 #求一个数的n次幂 4 print(i) C:\Python35\python3.exe F:/Python/2day/c6.py 32 Process finished with exit code 0
阅读全文
摘要:1 #!/usr/bin/env python 2 obj = iter([11,22,33,44]) 3 #iter 创建一个可以被迭代的对象 4 print(obj) 5 r1 = next(obj) 6 print(r1) 7 8 结果:C:\Python35\python3.exe F:/Python/2day/c4.py 11 Process finished wi...
阅读全文

浙公网安备 33010602011771号