当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python shutil.unregister_unpack_format()用法及代码示例


Python中的Shutil模块提供了许多对文件和文件集合进行高级操作的函数。它属于Python的标准实用程序模块。此模块有助于自动执行文件和目录的复制和删除过程。

shutil.unregister_unpack_format()Python中的方法用于从可用的受支持的解压缩格式列表中取消注册或删除解压缩格式。

我们还可以注册新格式或指定自己的函数,以使用以下格式解压缩现有格式shutil.register_unpack_format()方法或使用以下命令获取所有受支持的可用解压缩格式的列表shutil.get_unpack_formats()方法。


用法: shutil.unregister_unpack_format(name)

参数:
name:一个字符串,代表要从列表中删除的解压缩格式的名称。

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

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



相关用法


注:本文由纯净天空筛选整理自ihritik大神的英文原创作品 Python | shutil.unregister_unpack_format() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。