1) Simple application of ZipFile
If you are simply using Python for compression and decompression, the method is as follows
ImportZipfilef= ZipFile. ZipFile ('Filename.zip','W', ZipFile. zip_deflated) F.write ('1.txt') F.write ('2.doc') F.write ('3.zip') F.close () F.zipfile.zipfile ('Filename') F.extractall () f.close ()
* ZipFile. ZipFile (filename[, mode[, compression[, AllowZip64]])
* Mode and file operation, ' R ' means to open only one existing read-only zip file; ' W ' means to empty and open a write-only zip file, or to create a zip file that only writes; ' A ' means to open a zip file and add content.
Compression represents the compression format, there are only two alternative formats: Zip_store; Zip_deflated. Zip_store is the default, which means no compression; zip_deflated represents compression. When ALLOWZIP64 is true, 64-bit compression is supported.
2) ZipFile blasting zip script
Python version
· Python 2.7.12
Modules involved
· ZipFile
· Threading
Documents involved
· ZIP file
· TXT Password dictionary
#Coding:utf-8ImportZipFileImportThreadingdefzipbp (Zfile, pwd):Try: Zfile.extractall (pwd=pwd)Print 'password found:%s'%pwdexcept: returndefMain (): Zfile= ZipFile. ZipFile ('C.zip') Pwdall= Open ('Aa.txt') forPwdainchpwdall.readlines (): PWD= Pwda.strip ('\ n') T= Threading. Thread (TARGET=ZIPBP, args=(Zfile, pwd)) T.start () T.join ()if __name__=='__main__': Main ()
The ZipFile of the Python module