搜索文件,我想作出這樣的搜索,並行命令,對於給定字,給定數量的文件在哪裏?並行
ppatternsearch [-p n] word {files}
ppatternsearch
是命令名稱-p
是定義並行n
的水平的選擇是-p選項將 創建的字搜索的進程/線程的數目word
是我會尋找files
這個詞,你可以想像,我會通過被搜索的文件。
我想以兩種方式做到這一點 - 一個與processes
和另一個與threads
。最後,父進程/主線程返回找到正在搜索的單詞的行數。
事情是,我已經開發了一些代碼,並且我碰到了一堵牆。我不知道該從哪裏出發。
import argparse, os, sys, time
num_lines_with_pattern = []
def pattern_finder(pattern, file_searched):
counter = 0
with open(file_searched, 'r') as ficheiro_being_read:
for line in ficheiro_being_read:
if pattern in line:
print line
counter += 1
num_lines_with_pattern.append(counter)
parser = argparse.ArgumentParser()
parser.add_argument('-p', type = int, default = 1, help = Defines command parallelization.')
args = parser.parse_args()