目录
6万行的文本文件,python遍历查找和powerchell 查找方式对比
6万行的文本文件,python遍历查找和powerchell 查找方式对比
代码:
import os
import re
import subprocess
import time
if __name__ == '__main__':
file_path=r'./xxx.txt'
keywords = ['aaa', 'tracks.txt'] # 你的关键字列表
start = time.time()
with open(file_path, 'r',encoding='utf-8') as file:
for line_no, line in enumerate(file, start=1):
if all(keyword in line for keyword in keywords):
print(f'(line:{line_no}) {file_path}')
print('cost time1:', time.time()-start, 's')
start=time.time()
dir_path, file_name =