Python中的Shutil模塊提供了許多對文件和文件集合進行高級操作的函數。它屬於Python的標準實用程序模塊。此模塊有助於自動執行文件和目錄的複製和刪除過程。
shutil.unregister_unpack_format()Python中的方法用於從可用的受支持的解壓縮格式列表中取消注冊或刪除解壓縮格式。
我們還可以注冊新格式或指定自己的函數,以使用以下格式解壓縮現有格式shutil.register_unpack_format()方法或使用以下命令獲取所有受支持的可用解壓縮格式的列表shutil.get_unpack_formats()方法。
用法: shutil.unregister_unpack_format(name)
參數:
name:一個字符串,代表要從列表中刪除的解壓縮格式的名稱。
返回類型:此方法不返回任何值。
# Python program to explain shutil.unregister_unpack_format() method
# importing shutil module
import shutil
# Get the list of
# supported unpack formats
formats = shutil.get_unpack_formats()
# Print the list
print("Supported unpack formats:")
print(formats, "\n")
# Remove an unpack format
name = "gztar"
shutil.unregister_unpack_format(name)
print("%s unpack format unregistered successfully." %name, "\n")
# Get the list of
# supported unpack formats
formats = shutil.get_unpack_formats()
# Print the list
print("Supported unpack formats:")
print(formats, "\n")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’)]
參考: https://docs.python.org/3/library/shutil.html
相關用法
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python set()用法及代碼示例
- Python Decimal max()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
- Python os.rmdir()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python Decimal min()用法及代碼示例
- Python os.readlink()用法及代碼示例
- Python os.writev()用法及代碼示例
- Python os.readv()用法及代碼示例
- Python PIL RankFilter()用法及代碼示例
- Python os.rename()用法及代碼示例
- Python os.sendfile()用法及代碼示例
注:本文由純淨天空篩選整理自ihritik大神的英文原創作品 Python | shutil.unregister_unpack_format() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
