python解压zip文件

@staticmethod
def unzip_file(failed_file):
    zip_file = zipfile.ZipFile(failed_file)
    print(zip_file)
    if os.path.isdir(failed_file[0:-20]):
        pass
    else:
        os.mkdir(failed_file[0:-20])
    for names in zip_file.namelist():  # 解压
        zip_file.extract(names, failed_file[0:-20])
    zip_file.close()
    if os.path.exists(failed_file):  # 删除zip文件
        os.remove(failed_file)
    # print(failed_file[0:-20], '解压成功')

    return failed_file[0:-20]

 

posted @ 2021-06-07 13:42  test_yu  阅读(107)  评论(0编辑  收藏  举报