'Extracting the gz file using python ZIPFile [duplicate]

I'm using Python 2.7. I have the following code

file = ZipFile("D:\\Project\\text.evt.gz")

Its giving the following error

**"BadZipfile: File is not a zip file"**

While trying to extract the file manually,i am getting the following error

**"Unexpected end of data"**

Is it possible to extract the evt file irrespective of this error in Python? Basically i want to extract the compressed evt file to a specific destination folder.



Solution 1:[1]

The file extension "gz" suggests this is a gzip file, which is distinct from a zip file. Try the gzip module.

#!/usr/bin/env python3

import gzip
import sys


with gzip.open('/Some/file/somewhere.gz', 'rb') as f:
    file_content = f.read()

for i in file_content:
    print(chr(i),file=sys.stdout, end='')

Though it might make more sense to look into a system call to 7zip if you need this to be at all universal, and you don't have to manipulate the contents.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1