用这段代码可以用来打包自己的文件夹为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()