Skip to content
Advertisement

How to create a file object from a zipfile?

I want to create a file object from a file that is inside a zip. I don’t wanna extract that file. Actually I wanna use seek method on a file that is inside a zip. My code:

from zipfile import ZipFile
input_zip = ZipFile("xyz.zip")
file_name = input_zip.namelist()[0]
input_zip.read(name)

But I can’t use seek method on it. I wanna make it like this but without extracting the file:

file = open("new.txt", 'rb')
file.seek(14)

Advertisement

Answer

The documentation says seek is supported, you just need to open it the right way (as shown there).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement