发布时间:2019-09-27 07:09:13编辑:auto阅读(2048)
>>>import zipfile , os
//infomation for zip file
>>>zipFileHandle = zipfile.ZipFile('example.zip') //create zip file handle
>>>zipFileHandle.namelist() //return all files and directorys in the zip file
>>>spamInfo = zipFileHandle.getinfo('filename') //return a object of file in the zip file
>>>spamInfo.filename //return filename
>>>spamInfo.file_size //return file original size
>>>spamInfo.compress_size // file compressed size
>>>round(spamInfo.compress_size / spamInfo/file_size , 2) //compress rate
//unzip
>>>zipFileHandle.extractall() //unzip all to current directory
>>>zipFileHandle.extract('filename') //unzip 'filename' file to current directory
//close handle
>>>zipFileHandle.close()
//create a new zip file
>>>newZip = zipfile.ZipFile('new.zip','w')
>>>newZip.write('filename' , compress_type=zipfile.ZIP_DEFLATED)
>>>newZip.close()
//add files into a zip file
>>>zipFileHandle = zipfile.ZipFile('oldfile.zip' , 'a')
>>>zipFileHandle.write('filename' , compress_type=zipfile.ZIP_DEFLATED)
>>>>>>zipFileHandle.close()
上一篇: python3学习之对象
下一篇: python3学习之random
48618
47607
38406
35627
30074
26801
25806
20686
20430
18832
122°
197°
238°
253°
251°
254°
292°
348°
479°
463°