有没有办法在zip文件中的某个文件中搜索某些字符串而不解压缩?
我有以下目录结构:
.
├───some_zip_file.zip
│ ├──some_directory.SAFE
│ │ ├──some_dir
│ │ ├──some_another_dir
│ │ ├──manifest.safe \\ search in this file
答案 0 :(得分:0)
zipfile模块可以帮助您:
具体而言,您可以通过这种方式从zip中读取和存储文件的内容:
import zipfile
with zipfile.ZipFile("some_zip_file.zip", "r") as zip:
with zip.open("some_directory.SAFE/manifest.safe") as manifest:
content = manifest.read()
或:
import zipfile
with zipfile.ZipFile("some_zip_file.zip", "r") as zip:
content = zip.read("some_directory.SAFE/manifest.safe")