1
你怎麼壓縮「飛」生成的一堆文件?這種小規模之情況壓縮文件生成的文件
IM測試:
from time import strftime
import zipfile
# create new file
today = strftime("%Y-%m-%d %H:%M:%S")
new_file = open('testing123.txt', 'w')
text = 'this file was just added:' + str(today)
new_file.write(text)
# create zip file and write to it
newZip = zipfile.ZipFile("test.zip", "w")
newZip.write('testing123.txt')
new_file.close()
print "file created"
兩件事情,第一它是在腳本的頂部創建的testing123.txt
是空白的,當你解壓縮創建的zip文件,這應該包括列表在循環中生成的文件。
所以即時通訊想知道什麼是最好的方法來動態生成一堆文件,然後將它們全部壓縮到一個zip文件夾。
你應該第一個'new_file.close()'開始之前要郵編 – ozgur
您可以打開zip並繼續追加 – taesu