Python 7z 文件解压并实时显示进度条
使用 Python 的 py7zr 模块可以轻松解压 7z 文件。您可以使用以下代码来解压 'Python.7z' 文件到 'C:' 目录:
import py7zr
a = py7zr.SevenZipFile('Python.7z', mode='r')
a.extractall(r'C:\')
实时显示解压进度条
您可以使用 tqdm 模块来实现实时显示解压进度条。以下是示例代码:
import py7zr
from tqdm import tqdm
with py7zr.SevenZipFile('Python.7z', mode='r') as zip_file:
for member in tqdm(iterable=zip_file.list(), total=len(zip_file.list())):
zip_file.extract(member, path=r'C:\')
在上面的代码中,我们使用 tqdm 模块来迭代压缩文件的列表,并在每个迭代步骤中更新进度条。我们还使用了 Python 的上下文管理器来确保在完成解压缩后关闭 7z 文件。
原文地址: https://www.cveoy.top/t/topic/oito 著作权归作者所有。请勿转载和采集!