From the course: Python: Working with Files
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Extract from and write to TAR archives - Python Tutorial
From the course: Python: Working with Files
Extract from and write to TAR archives
- [Instructor] When you need to transfer several files, it can be useful to store them in an archive. tar is a common format for archiving a series of files, and we can use the tarfile module to create an archive. Let's say we want to create an archive of a few monster-related files. This will follow that same with-open pattern. We'll open the tarfile in write mode, and this will create that archive. From there, we can use the add function to add each file. Like with many write operations, this will overwrite any archived .tarfile that already exists. To append to an existing tarfile, we can use the append mode. We'll append the monsters_card03.png. This will add onto the tar archive without overwriting the previous content. Let's call these functions. We'll create the archive and then append to it. Here's our tar archive. Let's open it up. Inside, we have the PDF, PNG, and the CSV file. If you want to write to a…
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.