.tar.gz files are made by the combination of TAR packaging followed by a GNU zip (gzip) compression. These files are commonly used in Unix/Linux based system as packages or installers. In order to read or extract these files, we have to first decompress these files and after that expand them with the TAR utilities as these files contain both .tar and .gz files.
In order to extract or un-compress “.tar.gz” files using python, we have to use the tarfile module in python. This module can read and write .tar files including .gz, .bz compression methods.
- Import module
- Open .tar.gz file
- Extract file in a specific folder
- Close file
File in use
Link to download this file: Click here
Example: Printing file names before extracting
Example : Extract a specific file
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.