fork download
  1. '''
  2. I want a function which returns:
  3. dict("file1.txt": list(<contents of file1>),
  4. "file2.txt": list(<contents of file2>),
  5. "file3.txt": list(<contents of file3>),
  6. "file4.txt": list(<contents of file4>))
  7.  
  8. For input:
  9. file.zip:
  10. outer\
  11. outer\inner1.zip:
  12. file1.txt
  13. file2.txt
  14. outer\inner2.zip:
  15. file3.txt
  16. file4.txt
  17. '''
  18.  
  19. from zipfile import ZipFile, is_zipfile
  20.  
  21. def unarchive_all(input_zip):
  22. a=[]
  23. z = ZipFile(input_zip);
  24. for member in z.namelist():
  25. if is_zipfile(member):
  26. sub_z = ZipFile(file=z.open(member))
  27. for filename in sub_z.namelist():
  28. a.append(filename) # just for testing
  29. return a
  30.  
  31. if __name__ == "__main__":
  32. print unarchive_all('file.zip')
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty