導航:首頁 > 文件處理 > python壓縮gz

python壓縮gz

發布時間:2022-05-20 01:46:21

Ⅰ 求python的tar壓縮命令

rar_command = 'winrar a -r %s %s' % (target,source)

改為
rar_command = 'tar -zcvf %s %s' % (target,source)

Ⅱ python 在不解壓的情況下,怎麼得知壓縮包裡面文件的大小呢

可以使用 tarfile 模塊在不解壓的情況下查看壓縮包里文件的大小,代碼如下:

#coding=utf8

importtarfile
importos

tar=tarfile.open('G:/test/abc.tar.gz','r:gz')

fortiintar:
ifti.isreg():
print(ti.name,ti.size)

Ⅲ python如何判斷一個文件是否為gzip文件

本文實例講述了Python實現壓縮與解壓gzip大文件的方法。分享給大家供大家參考,具體如下:
#encoding=utf-8
#author: walker
#date: 2015-10-26
#summary: 測試gzip壓縮/解壓文件
import gzip
BufSize = 1024*8
def gZipFile(src, dst):
fin = open(src, 'rb')
fout = gzip.open(dst, 'wb')
in2out(fin, fout)
def gunZipFile(gzFile, dst):
fin = gzip.open(gzFile, 'rb')
fout = open(dst, 'wb')
in2out(fin, fout)
def in2out(fin, fout):
while True:
buf = fin.read(BufSize)
if len(buf) < 1:
break
fout.write(buf)
fin.close()
fout.close()
if __name__ == '__main__':
src = r'D:\tmp\src.txt'
dst = r'D:\tmp\src.txt.gz'
ori = r'D:\tmp\ori.txt'
gZipFile(src, dst)
print('gZipFile over!')
gunZipFile(dst, ori)
print('gunZipFile over!')

也可以簡單地封裝成一個類:
class GZipTool:
def __init__(self, bufSize):
self.bufSize = bufSize
self.fin = None
self.fout = None
def compress(self, src, dst):
self.fin = open(src, 'rb')
self.fout = gzip.open(dst, 'wb')
self.__in2out()
def decompress(self, gzFile, dst):
self.fin = gzip.open(gzFile, 'rb')
self.fout = open(dst, 'wb')
self.__in2out()
def __in2out(self,):
while True:
buf = self.fin.read(self.bufSize)
if len(buf) < 1:
break
self.fout.write(buf)
self.fin.close()
self.fout.close()

Ⅳ python如何按行獲取gz包中的數據

importos
importgzip

#那是因為你調用了read方法,而這個方法會把文件一股腦兒讀取出來的
#為了便於你迭代,你可以在這里使用一個生成器
defread_gz_file(path):
ifos.path.exists(path):
withgzip.open(path,'rt')aspf:
forlineinpf:
yieldline
else:
print('thepath[{}]isnotexist!'.format(path))


con=read_gz_file('abc.gz')
ifgetattr(con,'__iter__',None):
forlineincon:
print(line,end='')

Ⅳ python 如何批量解壓多個gz壓縮包

長按,後來繼續點擊解壓就可以全部解壓。

Ⅵ python如何讀取通過gzip壓縮的字元串

import osimport gzip # 那是因為你調用了read方法,而這個方法會把文件一股腦兒讀取出來的# 為了便於你迭代,你可以在這里使用一個生成器def read_gz_file(path): if os.path.exists(path): with gzip.open(path, 'rt') as pf: for line in pf: yield line else: print('the path [{}] is not exist!'.format(path)) con = read_gz_file('abc.gz')if getattr(con, '__iter__', None): for line in con: print(line, end = '')

Ⅶ python壓縮成tar

Python壓縮文件為tar、gzip的方源碼。需要應用到os、tarfile、gzip、string、shutil這幾個Python類庫中的方法。不同於Python Gzip壓縮與解壓模塊,今天我們要用自己的方法實現壓...

Ⅷ python 解壓縮tar.gz文件 判斷文件是否正常

  1. Python自帶的tarfile模塊可以方便讀取tar歸檔文件,牛b的是可以處理使用gzip和bz2壓縮歸檔文件tar.gz和tar.bz2。

  2. 對於gz格式gz文件一般不加密常見的是這種.tar.gz格式的 對於tar格式 在python標准庫我沒找到關於檢測加密的方法

Ⅸ python tar.gz怎麼安裝

tar.gz文件是在linux系統下的文件格式
.tar是把文件打成一個包,並不壓縮;
.gz是用gzip把打成包的.tar文件壓縮,所以成了一個.tar.gz的文件。

安裝的話,先解包,tar -zxvf python.tar.gz,這樣會生成一個以文件名命名的文件夾
有的文件直接這樣解壓即可,例如tomcat、eclipse
有的文件在解壓之後的文件中 有運行的腳本文件,如:start.sh 運行即可

閱讀全文

與python壓縮gz相關的資料

熱點內容
電腦遇到伺服器問題怎麼辦 瀏覽:514
加工中心編程結束方法 瀏覽:295
了解什麼是web伺服器 瀏覽:138
面向對象的編程的基本特徵 瀏覽:717
php定時執行任務linux 瀏覽:786
php數組中刪除元素 瀏覽:724
螢石雲伺服器視頻 瀏覽:269
防火牆配置伺服器熱備的虛擬地址 瀏覽:188
linux安裝xdm 瀏覽:736
java計算12 瀏覽:249
大金空調擺動式壓縮機 瀏覽:453
新的雲伺服器如何設置首頁 瀏覽:687
javastring字元位置 瀏覽:197
銀河麒麟字體庫存在哪個文件夾 瀏覽:957
魔獸加丁伺服器的航空叫什麼 瀏覽:152
花冠改裝案例哪個app多 瀏覽:515
成績單app哪個好用 瀏覽:140
北美程序員vs國內程序員 瀏覽:181
php解析xml文檔 瀏覽:121
石墨文檔APP怎麼橫屏 瀏覽:185