zip解压

import os,re
import zipfile
#解压密码探测
#解压默认为当前目录 8 行path设定
def unzip(password):
    z = zipfile.ZipFile(zip_path)#打开zip文件
    try:
        z.extractall(path=os.getcwd(),pwd= password.encode('utf-8'))#解压报错密码错误,不报错返回密码
        print('密码为:',password)
        return 1#不报错返回1
    except:
        return 0#报错返回0
#读入字典文件
def read_dictionary():
    with open(dictionary_path) as file: #打开文件
        for i in file.readlines(): #按行读入
            password = i.strip('\n') #删除密码后的\n
            if unzip(password): #密码返回值检测
                break
if __name__ == '__main__':
    dictionary_path=input("字典文件路径:")
    zip_path=input('压缩文件路径:')
    read_dictionary()

猜你喜欢

转载自blog.csdn.net/m0_37416991/article/details/81135593