如何从 zipfile 创建文件对象?

How to create a file object from a zipfile?

我想从 zip 中的文件创建文件对象。我不想提取那个文件。实际上我想在 zip 中的文件上使用 seek 方法。我的代码:

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

但是我不能在上面使用seek方法。我想这样做但不提取文件:

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

documentationseek 是支持的,你只需要以正确的方式打开它(如图所示)。