时间:2021-07-01 10:21:17 帮助过:307人阅读
用这段代码可以用来打包自己的文件夹为zip,我就用这段代码来备份
import zipfile z = zipfile.ZipFile('my-archive.zip', 'w', zipfile.ZIP_DEFLATED) startdir = "/home/johnf" for dirpath, dirnames, filenames in os.walk(startdir): for filename in filenames: z.write(os.path.join(dirpath, filename)) z.close()
希望本文所述对大家的Python程序设计有所帮助。