當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python shutil.unregister_archive_format()用法及代碼示例

Python中的Shutil模塊提供了許多對文件和文件集合進行高級操作的函數。它屬於Python的標準實用程序模塊。該模塊有助於自動執行文件和目錄的複製和刪除過程。

shutil.unregister_archive_format()Python中的方法用於從可用的支持存檔格式列表中注銷或刪除存檔格式。

我們還可以注冊新格式或使用以下函數指定自己的函數來歸檔現有格式shutil.register_archive_format()方法或使用以下命令獲取所有受支持的可用歸檔格式的列表shutil.get_archive_formats()方法。


用法: shutil.unregister_archive_format(name)

參數:
name:一個字符串,代表將從列表中刪除的存檔格式的名稱。

返回類型:此方法不返回任何值。

代碼:使用shutil.unregister_archive_format()方法
# 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



相關用法


注:本文由純淨天空篩選整理自ihritik大神的英文原創作品 Python | shutil.unregister_archive_format() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。