Python: search string in ziped files
<p>There is any way to search some string in some file in zip file without unziping?</p>

<p>I have following structure of directories:</p>

<pre><code>.
ââââsome_zip_file.zip
â   âââsome_directory.SAFE
â   â   âââsome_dir
â   â   âââsome_another_dir
â   â   âââmanifest.safe \\ search in this file
</code></pre>

<p>The <a href="https://docs.python.org/2/library/zipfile.html?highlight=zipfile#module-zipfile" rel="nofollow">zipfile</a> module could help you:</p>

<ul>
<li>It allows you to <a href="https://docs.python.org/2/library/zipfile.html?highlight=zipfile#zipfile.ZipFile.open" rel="nofollow">open</a> a file from the zip to get a file-like object</li>
<li>Or you can also directly <a href="https://docs.python.org/2/library/zipfile.html?highlight=zipfile#zipfile.ZipFile.read" rel="nofollow">read</a> a file from the archive</li>
</ul>

<p>concretly, you can read and store the content of a file from the zip this way:</p>

<pre><code>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()
</code></pre>

<p>or:</p>

<pre><code>import zipfile

with zipfile.ZipFile("some_zip_file.zip", "r") as zip:
    content = zip.read("some_directory.SAFE/manifest.safe")
</code></pre>

python zip