Python Glossary Русский

Python 3.2+shutilfunction

shutil.unregister_unpack_format()

archives

Removes a format from unpack_archive()'s registry and frees its extensions for another registration.

Syntax

shutil.unregister_unpack_format(name)

It is mainly needed before re-registering: while a format is registered its extensions are taken, and register_unpack_format fails on them with RegistryError. As with creation formats, an unknown name raises KeyError. After removal, unpack_archive on a file with that extension raises shutil.ReadError.

Examples

import shutil
shutil.register_unpack_format('lst', ['.lst'], lambda f, d: None)
shutil.unregister_unpack_format('lst')
shutil.register_unpack_format('lst2', ['.lst'], lambda f, d: None)
print([n for n, e, d in shutil.get_unpack_formats() if '.lst' in e])  # → ['lst2']
try:
    shutil.unregister_unpack_format('lst')
except KeyError as e:
    print(repr(e))  # → KeyError('lst')

See also

Open in the full glossarydocs.python.orgReport an inaccuracy