Python | shutil.unregister_unpack_format () method

Python Methods and Functions

shutil.unregister_unpack_format() in Python is used to unregister or remove an unpack format from the list of available supported unpack formats.

We can also register a new format or specify our own function to unpack existing formats using shutil.register_unpack_format() or get a list of all supported available unpacking formats using shutil.get_unpack_formats() .

Syntax: shutil.unregister_unpack_format (name)

Parameter:
name : A string representing the name of the unpack format which is to be removed from the list.

Return Type: This method does not return any value.

Code: using the shutil.unregister_unpack_format () method

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

 
# shutil module import

import shutil

 
# Get list
# unpacking formats supported

formats = shutil.get_unpack_formats ()

  
# Print list

print ( "Supported unpack formats:" )

print (formats, "" )

 
# Remove unpacking format

name = "gztar"

shutil.unregister_unpack_format (name)

print ( "% s unpack format unregistered successfully. " % name , "" )

 
# Get list
# unpacking formats supported

formats = shutil.get_unpack_formats ()

 
# Print list

print ( " Supported unpack formats: " )

print (formats, "" )

Output:

Supported unpack 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')]

'gztar' unpack format unregistered successfully.

Supported unpack formats:
[('bztar', ['.tar.bz2', '.tbz2'], “bzip2'ed tar-file ”), ('Tar', ['.tar'], 'uncompressed tar file'), ('xztar', ['.tar.xz', '.txz'],“ xz'ed tar-file ”) , ('zip', ['.zip'], 'ZIP file')]

Link: htt ps: //docs.python.org/3/library/shutil.html





Tutorials