Compression / decompression of zipfile

1


import zipfile
import glob

with zipfile.ZipFile('test.zip', 'w') as z:
    for f in glob.glob('test_dir/**', recursive=True):
        z.write(f)
#test_test under dir.Compress to zipfile with filename zip

with zipfile.ZipFile('test.zip', 'r') as z:
    z.extractall(path='zzz2')
#test in a directory called zzz2.Unzip the zip

2


import zipfile

with zipfile.ZipFile('test.zip', 'r') as z:
    with z.open('test_dir/sub_dir/sub_test.txt') as f:
        print(f.read())
#test compressed into a zip file.sub without unzipping_test.Output txt

Recommended Posts

Compression / decompression of zipfile
[Linux] tar.gz compression / decompression command
Basics of Quantum Information Theory: Data Compression (1)
I took a benchmark of h5py compression
Basics of Quantum Information Theory: Data Compression (2)