Python 官方文档:入门教程 => 点击学习
>>>import zipfile , os//infomation for zip file>>>zipFileHandle = zipfile.ZipFile('example.zip') //c
>>>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()
--结束END--
本文标题: python3 operate ZIP
本文链接: https://lsjlt.com/news/192849.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0