用python写一段接触压缩包密码的功能代码
时间: 2023-06-03 20:07:13 浏览: 86
以下是Python实现解压缩包解密密码的示例代码:
```python
import zipfile
def extract_zip_file(zip_file_path, password):
try:
with zipfile.ZipFile(zip_file_path) as zf:
zf.extractall(pwd=password.encode())
print("成功解压缩文件!")
except Exception as e:
print("错误提示:", str(e))
if __name__ == '__main__':
zip_file_path = '/path/to/zip/file.zip' # 压缩包文件路径
password = 'password123' # 压缩包密码
extract_zip_file(zip_file_path, password)
```
注:以上示例代码需要替换掉`zip_file_path`和`password`变量的实际值。
阅读全文