宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

本文章向大家介绍如何在python中将zip压缩包转换成gz.tar的基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Python主要用来做什么

Python主要应用于:1、Web开发;2、数据科学研究;3、网络爬虫;4、嵌入式应用开发;5、游戏开发;6、桌面应用开发。

#coding: utf-8

import os
import tarfile
import zipfile

def zip2tarroot_path, name,to_name='test'):

 '''
 root_path: 压缩文件所在根目录
 name: 压缩文件名字(zip格式)
 '''
 #root_path = r'C:\Users\Administrator\Desktop\somefiles'
 #file_path = os.path.joinroot_path, 'somemodel.zip')

 file_path = os.path.joinroot_path, name+'.zip')

 with zipfile.ZipFilefile_path, 'r') as zzip:
  with tarfile.openos.path.joinroot_path, to_name+'.gz.tar'), 'w') as ttar:
   for ffile in zzip.namelist):
    if not os.path.isdirffile):
    #if not ffile.strip).endswithr'/'):
     zzip.extractffile, root_path)
     ttar.addos.path.joinroot_path,ffile), arcname=ffile)


if __name__ == '__main__':

 root_path = raw_inputu'input root path: ')
 name = raw_inputu'input the zip namewithout .zip): ')
 zip2tarroot_path, name)