Python: Unzipping and decompressing .Z files inside .zip -


i trying unzip alpha.zip folder contains beta directory contains gamma folder contains a.z, b.z, c.z, d.z files. using zip , 7-zip able extract a.d, b.d, c.d, d.d files stored within .z files.

i tried in python using import gzip , import zlib.

import sys import os import getopt import gzip f = open('a.d.z','r') file_content = f.read() f.close() 

i keep getting sorts of errors including: not zip file, return codecs.charmap_encode(input self.errors encoding_map) 0. suggestions how code this?

you need make use of zip library of kind. right you're importing gzip, you're not doing it. try taking @ gzip documentation , opening file using library.

gzip_file = gzip.open('a.d.z') # use gzip.open instead of builtin open function file_content = gzip_file.read() 

edit based on comment: can't open kinds of compressed files compression library. since have .z file, it's want use zlib rather gzip, since extensions conventions, know sure compression format file in. use zlib, instead:

# note: untested code ahead! import zlib open('a.d.z', 'rb') f: # notice open in binary mode     file_content = f.read() # read compressed binary data     decompressed_content = zlib.decompress(file_content) # decompress 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -