python - Recursively unzip archives, store (filename, extracted-contents) in dictionary -
could please me write function returning:
dict("file1.txt": list(<contents of file1>), "file2.txt": list(<contents of file2>), "file3.txt": list(<contents of file3>), "file4.txt": list(<contents of file4>)) on input:
file.zip: outer\ outer\inner1.zip: file1.txt file2.txt outer\inner2.zip: file3.txt file4.txt my attempts (with exceptions below):
-
windowserror: [error 32] process cannot access file because being used process
-
"file not zip file"
-
"file not zip file"
-
attributeerror: zipfile instance has no attribute 'seek'
finally worked out... bit of from: extracting zipfile memory?;
from zipfile import zipfile, is_zipfile def extract_zip(input_zip): input_zip=zipfile(input_zip) return {name: input_zip.read(name) name in input_zip.namelist()} def extract_all(input_zip): return {entry: extract_zip(entry) entry in zipfile(input_zip).namelist() if is_zipfile(entry)}
Comments
Post a Comment