Python| shutil.unregister_archive_format() 方法
Python中的Shutil 模块提供了许多对文件和文件集合进行高级操作的功能。它属于 Python 的标准实用程序模块。该模块有助于自动化复制和删除文件和目录的过程。
Python中的shutil.unregister_archive_format()
方法用于从可用支持的存档格式列表中取消注册或删除存档格式。
我们还可以使用 shutil.register_archive_format() 方法注册新格式或指定自己的函数来归档现有格式,或者使用shutil.register_archive_format()
shutil.get_archive_formats()
获取所有支持的可用归档格式的列表。
Syntax: shutil.unregister_archive_format(name)
Parameter:
name: A string representing the name of the archive format which is to be removed from the list.
Return Type: This method does not return any value.
# Python program to explain shutil.unregister_archive_format() method
# importing shutil module
import shutil
# Get the list of
# supported archive formats
formats = shutil.get_archive_formats()
# Print the list
print("Supported archive formats:")
print(formats, "\n")
# Remove an archive format
name = "bztar"
shutil.unregister_archive_format(name)
print("'% s' archive format unregistered successfully." % name, "\n")
# Get the list of
# supported archive formats
formats = shutil.get_archive_formats()
# Print the list
print("Supported archive formats:")
print(formats, "\n")
Supported archive 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’)]
‘bztar’ archive format unregistered successfully.
Supported archive formats:
[(‘gztar’, “gzip’ed tar-file”), (‘tar’, ‘uncompressed tar file’), (‘xztar’, “xz’ed tar-file”), (‘zip’, ‘ZIP file’)]
参考: https://docs。 Python.org/3/library/shutil.html