简体   繁体   English

如何在python中为多个输出生成zip文件夹

[英]How to generate zip folder for multiple output in python

i am trying to build an application .Its working fine to genrate csv and pdf file .Now i want to generate an zip file which will contain both pdf and csv output how to do that?我正在尝试构建一个应用程序。它可以很好地生成 csv 和 pdf 文件。现在我想生成一个包含 pdf 和 csv 输出的 zip 文件,该怎么做?

my code:我的代码:

def save_analysis():
    file = asksaveasfile(mode='w', defaultextension=".csv", filetypes=[('CSV Files','*.csv')])
    print(file.name, "save file name")
    predict.generateCSV(adf,file.name)
    root.update()
    messagebox.showinfo("Saved Analysis", "Successfully Generated and Saved File to :\n" + file.name)

def view_stats():
    file = asksaveasfile(mode='w', defaultextension=".pdf", filetypes=[('Pdf Files','*.pdf')])
    print(file.name, "save file name")
    visual.show_visuals(adf,file.name)
    root.update()
    messagebox.showinfo("Visualization Saved", "Successfully Generated and Saved File to :\n" + file.name)

If you want to zip both pdf and csv as single zip file, you can use zipfile or shutil libraires.如果要将 pdf 和 csv 压缩为单个 zip 文件,可以使用zipfile或 shutil libraires。

Copy the files you want to zip under a folder and then use this code将要压缩的文件复制到文件夹下,然后使用此代码

import shutil
shutil.make_archive(output_filename, 'zip', folder_path)

For Zipfile, check this link .对于 Zipfile,请查看此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM