本文章向大家介紹如何在python中將zip壓縮包轉(zhuǎn)換成gz.tar的基本知識(shí)點(diǎn)總結(jié)和需要注意事項(xiàng),具有一定的參考價(jià)值,需要的朋友可以參考一下。
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、做網(wǎng)站、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、湘鄉(xiāng)ssl等。為數(shù)千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的湘鄉(xiāng)網(wǎng)站制作公司Python主要用來做什么Python主要應(yīng)用于:1、Web開發(fā);2、數(shù)據(jù)科學(xué)研究;3、網(wǎng)絡(luò)爬蟲;4、嵌入式應(yīng)用開發(fā);5、游戲開發(fā);6、桌面應(yīng)用開發(fā)。
#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)
以上就是小編為大家?guī)淼娜绾卧趐ython中將zip壓縮包轉(zhuǎn)換成gz.tar的全部內(nèi)容了,希望大家多多支持創(chuàng)新互聯(lián)!
分享標(biāo)題:如何在python中將zip壓縮包轉(zhuǎn)換成gz.tar-創(chuàng)新互聯(lián)
文章出自:http://bm7419.com/article42/dicsec.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、外貿(mào)網(wǎng)站建設(shè)、企業(yè)建站、網(wǎng)站收錄、定制網(wǎng)站、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容