Example of how to implement tar file compression and decompression in python,
Examples of downloading and downloading tar files using python
Compressed file:
Import tarfile import OS def tar (fname): t = tarfile. open (fname + ".tar.gz", "w: gz") for root, dir, files in OS. walk (fname): print root, dir, files for file in files: fullpath = OS. path. join (root, file) t. add (fullpath) t. close () if _ name _ = "_ main _": tar ("del ")
Decompress:
Import tarfile import OS def untar (fname, dirs): t = tarfile. open (fname) t. extractall (path = dirs) if _ name _ = "_ main _": untar ("del.tar.gz ",". ")
The dirs parameter is the path of the saved target file.
The above is an example of implementing tar file compression and decompression in python. If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article and hope to help you. Thank you for your support for this site!