本文章向大家介绍如何在python中将zip压缩包转换成gz.tar的基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
Python主要应用于:1、Web开发;2、数据科学研究;3、网络爬虫;4、嵌入式应用开发;5、游戏开发;6、桌面应用开发。
#coding: utf-8
import os
import tarfile
import zipfile
def zip2tar(root_path, name,to_name='test'):
'''
root_path: 压缩文件所在根目录
name: 压缩文件名字(zip格式)
'''
#root_path = r'C:\Users\Administrator\Desktop\somefiles'
#file_path = os.path.join(root_path, 'somemodel.zip')
file_path = os.path.join(root_path, name+'.zip')
with zipfile.ZipFile(file_path, 'r') as zzip:
with tarfile.open(os.path.join(root_path, to_name+'.gz.tar'), 'w') as ttar:
for ffile in zzip.namelist():
if not os.path.isdir(ffile):
#if not ffile.strip().endswith(r'/'):
zzip.extract(ffile, root_path)
ttar.add(os.path.join(root_path,ffile), arcname=ffile)
if __name__ == '__main__':
root_path = raw_input(u'input root path: ')
name = raw_input(u'input the zip name(without .zip): ')
zip2tar(root_path, name)
以上就是小编为大家带来的如何在python中将zip压缩包转换成gz.tar的全部内容了,希望大家多多支持亿速云!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。