Recursively unzip archives, store (filename, extracted-contents) in dictionary
dictionary, python, serialization, zip
Solution
Finally worked it out... with a bit of help from: Extracting a zipfile to memory?;
from zipfile import ZipFile, is_zipfile
def extract_zip(input_zip):
input_zip=ZipFile(input_zip)
return {name: input_zip.read(name) for name in input_zip.namelist()}
def extract_all(input_zip):
return {entry: extract_zip(entry) for entry in ZipFile(input_zip).namelist() if is_zipfile(entry)}
Problem
Could you please help me write a 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): http://ideone.com/s1tyb WindowsError: [Error 32] The process cannot access the file because it is being used by another process http://ideone.com/Y2oTw "File is not a zip file" http://ideone.com/0HoGa "File is not a zip file" http://ideone.com/owmdK AttributeError: ZipFile instance has no attribute 'seek'