python-zipfile

zip log files after it reach 10 backup count python

zip log files after it reach 10 backup count python Question: I am trying to zip logs once it reaches 10 backup counts in logging handler. Each log file am checking file size and am creating new file. Now if 10 files are getting created, for next file it should zip all logs and delete …

Total answers: 1

Opening PDF within a zip folder fitz.open()

Opening PDF within a zip folder fitz.open() Question: I have a function that opens a zip file, finds a pdf with a given filename, then reads the first page of the pdf to get some specific text. My issue is that after I locate the correct file, I can’t open it to read it. I …

Total answers: 2

Extracting Values From String

Extracting Values From String Question: I have a string generated from namelist() of ZipFile and I want to save in a variable only the filename of the pdf file: with ZipFile(zipfile, ‘r’) as f: filelist = f.namelist() print(filelist) The output is: [‘test.pdf’, ‘image_3.png’, ‘image-1.jpg’, ‘text-2.txt’] For example I want to store in the variable pdfname …

Total answers: 1

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

zipfile.BadZipFile: File is not a zip file when using "openpyxl" engine

zipfile.BadZipFile: File is not a zip file when using "openpyxl" engine Question: I have created a script which dumps the excel sheets stored in S3 into my local postgres database. I’ve used pandas read_excel and ExcelFile method to read the excel sheets. Code for the same can be found here. import boto3 import pandas as …

Total answers: 1

Pip cannot install wxPython for Python 3.10 (32-bit)

Pip cannot install wxPython for Python 3.10 (32-bit) Question: I have installed two frameworks of Python 3.10. There is wxPython310 for 64-bit Python. But there aren’t any wxPython for 32-bit Python. I tried to install wxPython with https://wxpython.org/Phoenix/snapshot-builds/wxPython-4.1.2a1.dev5259+d3bdb143.tar.gz, but it shows me the error code like this. Running setup.py install for wxPython … error error: …

Total answers: 4

Zipfile lib weird behaviour with seconds in modified time

Zipfile lib weird behaviour with seconds in modified time Question: Working with zipfile module I found something weird about how it works. I’m zipping one file, which last modified attr time is: 13:40:31 (HH:MM:SS) When I zip and unzip the file, its last mod time is 13:40:30 (lost 1 second) Doing some tests around this, …

Total answers: 1

OSError Invalid argument when extracting with Python zipfile on Linux

OSError Invalid argument when extracting with Python zipfile on Linux Question: I want to extract a file within a .zip archive to another directory. First I create a ZipFile object zfile = ‘/home/…/filename.zip’ archive = zipfile.ZipFile(zfile, ‘r’) The triple dot … is me just hiding the full path, not there in the real path. Then …

Total answers: 3

How to eliminate absolute path in zip archive if absolute paths for files are provided?

How to eliminate absolute path in zip archive if absolute paths for files are provided? Question: I have two files in two different directories, one is ‘/home/test/first/first.pdf’, the other is ‘/home/text/second/second.pdf’. I use following code to compress them: import zipfile, StringIO buffer = StringIO.StringIO() first_path = ‘/home/test/first/first.pdf’ second_path = ‘/home/text/second/second.pdf’ zip = zipfile.ZipFile(buffer, ‘w’) zip.write(first_path) …

Total answers: 6