

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How we can compress large Python files?
We can use Python to compress or extract files. We use the zipfile module in Python, to extract or compress individual or multiple files at once. This process is is easy and requires very little code. We begin by importing the zipfile module and then open the ZipFile object in write mode by specifying the second parameter as 'w'. The file to be zipped is in the same folder as this code file or the path of the file to be zipped can be specified instead. Here is the code that you need −
import zipfile foo_zip = zipfile.ZipFile ( 'foo.zip', 'w' ) foo_zip.write ( 'foo.txt', compress_type=zipfile.ZIP_DEFLATED ) foo_zip.close ()
This creates zipped file foo.zip from the file foo.txt
- Related Questions & Answers
- How to Compress files with ZIPFILE module in Python.
- How we can split Python class into multiple files?
- Sending large files over internet
- How to stream large .mp4 files in HTML5?
- How to download large files through PHP script?
- How to Handle Large CSV files with Pandas?
- How to upload large files above 500MB in PHP?
- How can we transfer information between MySQL and data files?
- How can we import CSV files into MySQL tables by using mysqlimport?
- How to split or break large files into pieces in Linux?
- How to compress Python objects before saving to cache?
- Splitting and uploading extremely large files to Amazon S3
- How can we transfer information between MySQL and data files through command line?
- How to compress and un-compress the data of a file in Java?
- The best way to compress and extract files using the tar command on linux
Advertisements