December 2018
Beginner to intermediate
796 pages
19h 54m
English
Before we leave this section, let me give you an example of how to create a compressed file. In the source code of the book, I have two examples: one creates a ZIP file, while the other one creates a tar.gz file. Python allows you to create compressed files in several different ways and formats. Here, I am going to show you how to create the most common one, ZIP:
# files/compression/zip.pyfrom zipfile import ZipFilewith ZipFile('example.zip', 'w') as zp: zp.write('content1.txt') zp.write('content2.txt') zp.write('subfolder/content3.txt') zp.write('subfolder/content4.txt')with ZipFile('example.zip') as zp: zp.extract('content1.txt', 'extract_zip') zp.extract('subfolder/content3.txt', 'extract_zip')
In the preceding ...
Read now
Unlock full access