如何解决如何使用python解压缩和解压缩?
因此,我需要访问压缩文件夹(也为tar)中的文件和文件夹。用户提供存在此Gunzip文件的路径,并从python代码中提取路径,我需要将所有这些文件解压缩,解压缩并将其解压缩到同一位置,然后访问此目录中的文件和文件夹。
path given by user - C:/Users/user1/Desktop/tar_gz/tarball.tar.xz
文件应提取到同一目录-C:/ Users / user1 / Desktop / tar_gz / tarball
我对机器学习的概念是陌生的,很难解决这个问题。有什么方法可以做到这一点?
解决方法
import tarfile
import os
path_tofile = r"C:/Users/user1/Desktop/tar_gz/tarball.tar.xz"
extract_direcotry = os.path.dirname(path_tofile)
if tarfile.is_tarfile(path_tofile):
with tarfile.open(path_tofile) as f:
f.extractall(path=extract_direcotry) # Extract all members from the archive to the current working directory
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。