From the course: Python: Working with Files
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Read from and extract ZIP archives - Python Tutorial
From the course: Python: Working with Files
Read from and extract ZIP archives
- [Instructor] Whether you want to read a zip file or extract all the data from an archive, it's important to be able to access your files in Python, no matter the format. Let's look at how to read a zip file and extract files from it using Python. To work with zip files, we can use the zip file module. To get information about a zip file, we can create a zip file object and open it in read mode. We will read the archive.zip file, and we'll refer to it as archive in our program. When reading a zip file, we can see what files are in it with archive.namelist. Let's print it out to the console and see what's in our archive. We'll execute it in the terminal. And there's two files, description one and description two, both text files. Given these file names, we can use one of them when reading the zip file to get more information about that file. Let's say we wanted to get more information about description one. We'll…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.