python零碎知识
张羽翔
这个作者很懒,什么都没留下…
展开
-
python 正则 匹配多个字符、分组
re.match(r"速度与激情\d{1,2}", "速度与激情12") ? :一个,没有。 * : 一个 , 多个, 没有 + : 一个, 多个, 不能没有 . 不能匹配换行 re.S : 匹配换行符, 并且打印出来 match 默认匹配开头,不匹配结尾 ^ 开头 $结尾 正则分组 字符 功能 | 匹配左右任意一个表达式 (ab) 将括号中字符作为一个...原创 2020-04-19 19:07:37 · 505 阅读 · 1 评论 -
python 中的正则表达式---匹配单个字符
re.match(r"hello", "hello, world") -------------------------------------------- re.match(r"[hH]ello", "hello, world") -------------------------------------------- ret = re.match(r"速度与激情\d", "速度与激情8)...原创 2020-04-19 14:35:21 · 241 阅读 · 0 评论 -
创建队列
q = multiprocessing.Manager().Queue() # 先创建一个对象,再调用queue方法实现进程间的通信 #向队列中写入一个消息 q.put(file_name) #接收 while True: file_name = q.get() print(已经读取了%s" file_name) if ***: break p...原创 2020-04-18 17:26:24 · 135 阅读 · 0 评论 -
创建进程池
import multiprocessing import os def copy_file(file_name): file_names = os.listdir(old_folder_name) po = multiprocessing.Pool(5) # 创建进程池 for file_name in file_names: # 向进程池中添加copy文件的任务 ...原创 2020-04-18 17:03:12 · 103 阅读 · 0 评论 -
避免重复创建文件夹
try: os.mkdir(old_folder_name + "[复件]") except: pass原创 2020-04-18 15:40:46 · 479 阅读 · 0 评论