Python Zipfile module is throwing errors

Viewed 274

I'm trying to get a python Zip module to compress data.

But all it's doing is throwing an error:

with ZipFile(O_file7,mode='w',compression=ZipFile.ZIP_DEFLATED,compressionlevel=9) as file:
AttributeError: type object 'ZipFile' has no attribute 'ZIP_DEFLATED'

I've tried using

ZipFile.ZIP_DEFLATED, and

zipfile.ZipFile.ZIP_DEFLATED, but get the exact same result.

If I remove the compression and compression level parameters, the code runs just fine, but the whole point of using it is to compress the data.

Any help would be greatly appreciated.

Here is the code.

    import zlib
    from zipfile import ZipFile
    HOME2 = "h:\\\\passport\\tran-14d - ollw mass print\\"
    ARCHIVE = HOME2+"\\Archive\\"
    I_file1 = "masterfile.txt"             
    O_file7 = "New.zip" 
    def ZIPPER():
        os.chdir(HOME2)
        with ZipFile(O_file7,mode='w',compression=ZipFile.ZIP_DEFLATED,compressionlevel=9) as file:
            os.chdir(HOME2)
            file.write(I_file1)
1 Answers
Related