zip

Python Regex to extract file where filename contains and also should not contain specific pattern from a zip folder

Python Regex to extract file where filename contains and also should not contain specific pattern from a zip folder Question: I want to extract just one specific single file from the zip folder which has the below 3 files. Basically it should start with ‘kpidata_nfile’ and should not contain ‘fileheader’ kpidata_nfile_20220919-20220925_fileheader.csv kpidata_nfile_20220905-20220911.csv othername_kpidata_nfile_20220905-20220911.csv Below is …

Total answers: 1

Rename files in subdirectories with the root directory name in an zipfile

Rename files in subdirectories with the root directory name in an zipfile Question: I have the following directory structure within my zip file: myzip.zip – directory 1 – subdirectory 1 – imageA.jpg – imageB.jpg – directory 2 – subdirectory 2 – imageA.jpg – imageB.jpg And my goal is to rename the .jpg files to main …

Total answers: 2

Why do Python zipapps get slower the bigger they get?

Why do Python zipapps get slower the bigger they get? Question: I have a python zipapp (specifically, of pdm). When running from the filesystem, it takes around 0.300s just to show the help page. However, with my zipapp, its 1s. The zipapp is around 25 MB (it includes all of the dependencies). Getting a file …

Total answers: 1

Python zipfile just creates empty folders with no content

Why does Python's zipfile create empty folders with no content? Question: I am working on a Google Colab notebook. I have downloaded datasets from Kaggle and it is in zip format. I have used Python’s zipfile module but I don’t see it working. Looks like it just created empty folders but I don’t see contents …

Total answers: 1

How to zip a file in python?

How to zip a file in python? Question: I have been trying to make a python script to zip a file with the zipfile module. Although the text file is made into a zip file, It doesn’t seem to be compressing it; testtext.txt is 1024KB whilst testtext.zip (The code’s creation) is also equal to 1024KB. …

Total answers: 3

How do I save a FastAPI UploadFile which is a zip file to disk as .zip?

How do I save a FastAPI UploadFile which is a zip file to disk as .zip? Question: I’m uploading zip files as UploadFile via FastAPI and want to save them to the filesystem using async aiofiles like so: async def upload(in_file: UploadFile = File(…)): filepath = /path/to/out_file.zip async with aiofiles.open(filepath, ‘wb’) as f: while buffer …

Total answers: 1

Printing a zip from dictionary return Empty list

Printing a zip from dictionary return Empty list Question: I am performing this simple zip in python from a dictionary and I am not sure why the second time I do it it gives me an empty list. l1= {‘a’:6, ‘b’:5, ‘c’:3, ‘d’:2, ‘e’:1, ‘f’:7, ‘g’:4, ‘h’:9} l2={‘a’:7, ‘b’:5, ‘c’:2, ‘d’:3, ‘e’:8} z=zip(l1.values(),l2.values()) print(list(z)) #This …

Total answers: 1

Why I'm getting empty list after using zip in python?

Why I'm getting empty list after using zip in python? Question: After I zip two lists and print the zip object as a list, I get the desired output. But when I wanted to make another list from the zip object I get an empty list. Why this is happening? Code: result = zip(number_list, str_list) …

Total answers: 2

Split a zip-file into chunks with Python

Split a zip-file into chunks with Python Question: I have a piece of a code which creates a zip file successfully, but I need to split this file if the size of it is more that 1MB. I have this code but it doesn’t work: from split_file_reader.split_file_writer import SplitFileWriter import zipfile # make element tree …

Total answers: 2

How to zip all outputs (*.csv and *.tiff) in jupyter notebook

How to zip all outputs (*.csv and *.tiff) in jupyter notebook Question: I use this command ! zip -r results.zip . -i *.csv *.pdf in Jupyter Notebook(Python 3.7.10) in order to zip all the output files. But, it shows zip’ is not recognized as an internal or external command, operable program or batch file. Can …

Total answers: 2