亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python中將zip壓縮包轉(zhuǎn)為gz.tar的方法

 更新時(shí)間:2018年10月18日 15:42:13   作者:曉東邪  
今天小編就為大家分享一篇python中將zip壓縮包轉(zhuǎn)為gz.tar的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

由于同事電腦上沒(méi)有直接可以壓縮gz.tar格式的壓縮軟件,而工作中這個(gè)又時(shí)常需要將zip文件轉(zhuǎn)換為gz.tar格式,所以常常將壓縮為zip格式的文件發(fā)給我來(lái)重新壓縮成gz.tar格式發(fā)給他,能偷懶就不想動(dòng)手,就用python的tarfile和zipfile包完成了一個(gè)將zip轉(zhuǎn)換成gz.tar格式的小腳本:

代碼比較簡(jiǎn)單,也就幾行,但是寫(xiě)的時(shí)候因?yàn)榻^對(duì)路徑的問(wèn)題浪費(fèi)了點(diǎn)時(shí)間,代碼水平還是有待提高。

#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壓縮包轉(zhuǎn)為gz.tar的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論