我必須提取數百個大小爲5GB的tar.bz文件。因此,嘗試下面的代碼:使用Python提取tar文件的最快方法
import tarfile
from multiprocessing import Pool
files = glob.glob('D:\\*.tar.bz') ##All my files are in D
for f in files:
tar = tarfile.open (f, 'r:bz2')
pool = Pool(processes=5)
pool.map(tar.extractall('E:\\') ###I want to extract them in E
tar.close()
但代碼有錯誤類型: 類型錯誤:地圖()至少需要3個參數(2給出)
我該如何解決呢? 任何進一步的想法,以加速提取?
我打賭你的問題在這裏是I/O而不是代碼。 'map'錯誤很明顯:你必須提供一個函數和該函數的參數列表。你的情況:'map(extractall,[list,of,files])' – xbello 2014-09-21 15:12:41
如何提供目標目錄?地圖(extractall,[list,of,files]) – Beau 2014-09-21 15:16:45
每個文件有不同的目標? '[(list,dest),(of,dest2),(files,dest3)]'。相同的目標?爲'extractall'創建一個'functools.partial'。 – xbello 2014-09-21 15:18:30