简体   繁体   English

如何从 zip 文件创建文件 object?

[英]How to create a file object from a zipfile?

I want to create a file object from a file that is inside a zip.我想从 zip 中的文件创建文件 object。 I don't wanna extract that file.我不想提取那个文件。 Actually I wanna use seek method on a file that is inside a zip.实际上我想对 zip 内的文件使用 seek 方法。 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.但我不能在上面使用 seek 方法。 I wanna make it like this but without extracting the file:我想让它像这样但不提取文件:

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

The documentation says seek is supported, you just need to open it the right way (as shown there). 文档说支持seek ,您只需要以正确的方式打开它(如图所示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM