【发布时间】:2021-12-19 09:13:24
【问题描述】:
这是三个文件名(在这个例子中,里面的内容应该无关紧要):
File1.txt
File2.txt
File3.txt
这是我当前的代码:
# create new .txt files
newFile1 = open('File1.txt', 'w')
newFile2 = open('File2.txt', 'w')
newFile3 = open('File3.txt', 'w')
# compress these three newly created files into a .zip folder
我的目标是在脚本执行时创建一个压缩上面列出的三个文件的 .zip 文件。
这是我想要的输出(一个新创建的 .zip 文件):
CompressedFolder.zip
【问题讨论】:
-
Python 有 zipfile 库 docs.python.org/3/library/zipfile.html 打开一个 zip 文件并将您的三个文件写入其中。
-
你会发现this很有帮助
标签: python