From the course: Python Standard Library Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Working with ZIP files

Working with ZIP files - Python Tutorial

From the course: Python Standard Library Essential Training

Start my 1-month free trial

Working with ZIP files

- [Teacher] ZIP files have been around for decades now and are a very common way of distributing and packaging a collection of files into an easy to distribute single file archive. With Python you can easily create, inspect, modify, and unpack these files. Here in the zipfile_start example I've imported the ZIP file module which gives us access to the functions we're going to need. So first let's try creating a ZIP file. So here in my folder you can see these three text files. Let's add these files to a new ZIP archive. So to do that I actually need to create a new ZIP file object with write permission. So I'll say zfile is equal to zipfile.Zipfile, and I'll name it archive.zip, and I need write permission to write the data, and then let's add each of the files. So I'll write file1.txt, and then oops, I'll do that again for files two and three, and then I need to close the file when I'm done. Alright so let's run this, and you can see that the ZIP file is created right there. Now we…

Contents