The ZipFile of the Python module

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.