Skip to content
Advertisement

Tag: zip

Why does compression output a larger zip file?

I really don’t understand about python compression because whenever I am trying to compress a folder or file I end up getting a very larger file 5.5 times bigger than the original file. Why does this happen? Is there any way I can compress a folder or a file with python and get an output that’s at most the size

zip file and avoid directory structure

I have a Python script that zips a file (new.txt): When I do this I get the zip file. But when I try to unzip the file I get the text file inside of a series of directories corresponding to the path of the file i.e I see a folder called root in the result directory and more directories within

Python zipfile, How to set the compression level?

Python supports zipping files when zlib is available, ZIP_DEFLATE see: https://docs.python.org/3.4/library/zipfile.html The zip command-line program on Linux supports -1 fastest, -9 best. Is there a way to set the compression level of a zip file created in Python’s zipfile module? Answer Starting from python 3.7, the zipfile module added the compresslevel parameter. https://docs.python.org/3/library/zipfile.html I know this question is dated, but

Using Python to add a list of files into a zip file

I want to write a script to add all the ‘.py’ files into a zip file. Here is what I have: However it gives an error: so seems the file names given is not correct. Answer You need to pass in the compression type as a keyword argument: Without the keyword argument, you are giving ZipFile.write() an integer arcname argument

in Numpy, how to zip two 2-D arrays?

For example I have 2 arrays How can I zip a and b so I get ? Answer You can use dstack: If you must have tuples: For Python 3+ you need to expand the zip iterator object. Please note that this is horribly inefficient:

Python script to check if a zip file is corrupt

How do I check if a zip file is corrupt or not? I have a zip file with 10 jpg images. I am able to extract say 8 of the images. Two of the images in the zip are corrupt and I am not able to extract those. Is there a way to check for this in a Python script?

Using Python, getting the name of files in a zip archive

I have several very large zip files available to download on a website. I am using Flask microframework (based on Werkzeug) which uses Python. Is there a way to show the contents of a zip file (i.e. file and folder names) – to someone on a webpage – without actually downloading it? As in doing the working out server side.

Create a zip file from a generator in Python?

I’ve got a large amount of data (a couple gigs) I need to write to a zip file in Python. I can’t load it all into memory at once to pass to the .writestr method of ZipFile, and I really don’t want to feed it all out to disk using temporary files and then read it back. Is there a

Advertisement