Python | shutil.get_unpack_formats () method

Python Methods and Functions

shutil.get_unpack_formats() in Python is used to get a list of all supported formats available for unpacking archive files. 
The following formats are available for unpacking archive files by default:

  • ZIP: ZIP file. If zlib module is available
  • tar: uncompressed tar file.
  • gztar : gzip archive. If zlib module is available
  • tar file bztar: bzip2. If bz2 module is available
  • xztar: xz & # 39; ed tar file. If the module is available lzma

We can also register new formats or specify our own function to unpack existing formats using shutil.register_unpack_format () or shutil.register_unpack_format() registering an existing format with shutil.unregister_unpack_format () .

Syntax: shutil .get_unpack_formats ()

Parameter: No parameter is required

Return Type: This method returns a list which represents the available formats supported for unpacking archived files. Each element of the list is a tuple (name, extension description).

Code: using the shutil.get_unpack_formats () method

# Python program to explain the shutil.get_unpack_formats () method

# shutil module import

import shutil

# Get list
# supported unpacking formats

formats = shutil. get_unpack_formats ()


# Print list

print ( "Supported unpacking formats:" , formats)


 Supported unpacking formats: Supported unpacking formats: [('bztar', [' .tar.bz2', '.tbz2']," bzip2'ed tar-file "), (' gztar', ['.tar.gz',' .tgz'], "gzip'ed tar-file"), ('tar', [' .tar'], 'uncompressed tar file'), (' xztar' , ['.tar.xz',' .txz'], "xz'ed tar-file"), ('zip', [' .zip'], 'ZIP file')]