1.zip 解压缩
import os | |
import zipfile | |
target_file = r",/file.zip" | |
extract_path = "./data" | |
def unzip_file(zip_file_path, extract_to_path): | |
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref: | |
zip_ref.extractall(extract_to_path) | |
print('Extract zip file finished!') | |
unzip_file(target_file, extract_path) |
2. tar 解压缩
import tarfile | |
def untar_file(tar_file_path, extract_to_path): | |
with tarfile.open(tar_file_path, 'r') as tar_ref: | |
tar_ref.extractall(extract_to_path) |
3.tar.gz 解压缩
import tarfile | |
def untar_gz_file(tar_gz_file_path, extract_to_path): | |
with tarfile.open(tar_gz_file_path, 'r:gz') as tar_gz_ref: | |
tar_gz_ref.extractall(extract_to_path) |
正文完