本文介绍了Python代码创建密码加密的zip文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建密码加密的 zip 文件的 Python 代码是什么?我可以在命令行上使用 system 使用一些 apt-get'able 实用程序.
解决方案
使用开源 实用程序:
rc = subprocess.call(['7z', 'a', '-pP4$$W0rd', '-y', 'myarchive.zip'] +['first_file.txt', 'second.file'])
要安装 7-Zip,请键入:
$ sudo apt-get install p7zip-full
要手动解压缩(以证明与 zip 实用程序的兼容性),请键入:
$ unzip myarchive.zip
然后在提示处输入P4$$W0rd
.
或在 Python 2.6+ 中相同:
>>>zipfile.ZipFile('myarchive.zip').extractall(pwd='P4$$W0rd')What is the Python code to create a password encrypted zip file? I'm fine with using some apt-get'able utilities using system on the command line.
解决方案
To create encrypted zip archive (named 'myarchive.zip'
) using open-source 7-Zip
utility:
rc = subprocess.call(['7z', 'a', '-pP4$$W0rd', '-y', 'myarchive.zip'] +
['first_file.txt', 'second.file'])
To install 7-Zip, type:
$ sudo apt-get install p7zip-full
To unzip by hand (to demonstrate compatibility with zip utitity), type:
$ unzip myarchive.zip
And enter P4$$W0rd
at the prompt.
Or the same in Python 2.6+:
>>> zipfile.ZipFile('myarchive.zip').extractall(pwd='P4$$W0rd')
这篇关于Python代码创建密码加密的zip文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!