Python 解压文件

Python 解压文件,python,zipfile,Python,Zipfile,我想解压一个*.sec.gz类型的文件,它是一个zipfile文件。但是我收到了坏文件…有人能帮我解决这个问题吗…文件夹中的文件类型是*.sec…。提前谢谢 import zipfile def unzip(path): zfile = zipfile.ZipFile(path) for name in zfile.namelist(): (dirname, filename) = os.path.split(name) if filename =

我想解压一个*.sec.gz类型的文件,它是一个zipfile文件。但是我收到了坏文件…有人能帮我解决这个问题吗…文件夹中的文件类型是*.sec…。提前谢谢

import zipfile
def unzip(path):
    zfile = zipfile.ZipFile(path)
    for name in zfile.namelist():
        (dirname, filename) = os.path.split(name)
        if filename == '':
            # directory
            if not os.path.exists(dirname):
                os.mkdir(dirname)
        else:
            # file
            fd = open(name, 'w')
            fd.write(zfile.read(name))
            fd.close()
    zfile.close()

k=unzip('C://test//08October2014//DATA_INTV_NEW//Oct0814//1.sec.gz')
输出:

BadZipfile                                Traceback (most recent call last)
<ipython-input-7-5134b63e752e> in <module>()
     27     zfile.close()
     28 
---> 29 k=unzip('C://test//08October2014//DATA_INTV_NEW//Oct0814//1.sec.gz')

<ipython-input-7-5134b63e752e> in unzip(path)
     13 
     14 def unzip(path):
---> 15     zfile = zipfile.ZipFile(path)
     16     for name in zfile.namelist():
     17         (dirname, filename) = os.path.split(name)

C:\Python27\Lib\zipfile.pyc in __init__(self, file, mode, compression, allowZip64)
    768         try:
    769             if key == 'r':
--> 770                 self._RealGetContents()
    771             elif key == 'w':
    772                 # set the modified flag so central directory gets written

C:\Python27\Lib\zipfile.pyc in _RealGetContents(self)
    809             raise BadZipfile("File is not a zip file")
    810         if not endrec:
--> 811             raise BadZipfile, "File is not a zip file"
    812         if self.debug > 1:
    813             print endrec

BadZipfile: File is not a zip file
BadZipfile回溯(最近一次调用)
在()
27 zfile.close()
28
--->29 k=unzip('C://test//08October2014//DATA\u INTV\u NEW//Oct0814//1.sec.gz')
在解压中(路径)
13
14 def解压缩(路径):
--->15 zfile=zipfile.zipfile(路径)
16用于zfile.namelist()中的名称:
17(dirname,filename)=os.path.split(name)
C:\Python27\Lib\zipfile.pyc在uuu init_uuuu中(self、file、mode、compression、allowZip64)
768试试:
769如果键=='r':
-->770 self.\u RealGetContents()
771 elif键=='w':
772#设置修改标志以便写入中心目录
C:\Python27\Lib\zipfile.pyc in\u RealGetContents(self)
809 raise BadZipfile(“文件不是zip文件”)
810如果不是endrec:
-->811 raise BadZipfile,“文件不是zip文件”
812如果self.debug>1:
813打印结束
BadZipfile:文件不是zip文件

错误消息完全准确:这不是zip文件。它是一个gzip文件,这是完全不同的。您应该使用。

错误消息完全准确:这不是zip文件。它是一个gzip文件,这是完全不同的。您应该使用。

错误消息完全准确:这不是zip文件。它是一个gzip文件,这是完全不同的。您应该使用。

错误消息完全准确:这不是zip文件。它是一个gzip文件,这是完全不同的。您应该使用。

感谢您的指导,能够使用gzip检索。open()感谢您的指导,能够使用gzip检索。open()感谢您的指导,能够使用gzip检索。open()感谢您的指导,能够使用gzip检索。open()感谢您的指导,能够使用gzip.open()检索