新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

如何在python中将zip压缩包转换成gz.tar-创新互联

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

我们提供的服务有:成都网站建设、做网站、微信公众号开发、网站优化、网站认证、湘乡ssl等。为数千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的湘乡网站制作公司Python主要用来做什么

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的全部内容了,希望大家多多支持创新互联!


网页名称:如何在python中将zip压缩包转换成gz.tar-创新互联
文章路径:http://www.wjwzjz.com/article/dicsec.html
在线咨询
服务热线
服务热线:028-86922220
TOP