Skip to content

Instantly share code, notes, and snippets.

@pedrovanzella
Last active September 24, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrovanzella/13fdb296c7b1e481168dfbb502aab4a2 to your computer and use it in GitHub Desktop.
Save pedrovanzella/13fdb296c7b1e481168dfbb502aab4a2 to your computer and use it in GitHub Desktop.
Try to unzip a file in a flat hierarchy
import zipfile
import os
from typing import List
def extract(file: str, path: str=".") -> List[str]:
names = []
with zipfile.ZipFile(file) as zip_file:
for member in zip_file.namelist():
data = zip_file.read(member)
file_name = member.split('/')[-1]
if not file_name:
continue
with open(os.path.join(path, file_name), "wb") as f:
f.write(data)
names.append(file_name)
return names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment