Python and the zipfile module

ぃ、小莉子 提交于 2019-12-02 11:36:06

Rather than use extract(), you can use ZipFile.open() and copy the file to a filename of your own choosing; use shutil.copyfileobj() to efficiently copy the data across:

import shutil

archive = zipfile.ZipFile(ifile)
path = os.path.join('/2015/MyCODE', folderName)

for name in aidlist_to_keep:
    try:
        archivefile = archive.open(name)
    except KeyError:
        # no such file in the archive
        continue
    with open(os.path.join(path, name), 'wb') as targetfile:
        shutil.copyfileobj(archivefile, targetfile)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!