extract files inside zip sub folders with python zipfile
<p>i have a zip folder that contains files and child zip folders. I am able to read the files placed in the parent folder but how can i get to the files inside the child zip folders? here is my code to get the files inside the parent folder</p>

<pre><code>from io import BytesIO
import pandas as pd
import requests
import zipfile
url1 = 'https://www.someurl.com/abc.zip'
r = requests.get(url1)
z = zipfile.ZipFile(BytesIO(r.content))    
temp  = pd.read_csv(z.open('mno.csv')
</code></pre>

<p>my question is, if lets say, I have a child sub folder </p>

<pre><code>xyz.zip 
</code></pre>

<p>containing file</p>

<pre><code>pqr.csv
</code></pre>

<p>how can I read this file</p>

<p>After trying some permutation-combination, i hatched the problem with this code</p>

<pre><code>zz = zipfile.ZipFile(z.namelist()[i])
temp2  = pd.read_csv(zz.open('pqr.csv'))
# where i is the index position of the child zip folder in the namelist() list. In this case, the 'xyz.zip' folder

# for eg if the 'xyz.zip' folder was third in the list, the command would be:
zz = zipfile.ZipFile(z.namelist()[2])
</code></pre>

<p>alternatively, if the index position is not known, the same can be achieved like this:</p>

<pre><code>zz  = zipfile.ZipFile(z.namelist()[z.namelist().index('xyz.zip')])
</code></pre>

python pandas zipfile