-1

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?

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)
vahdet
  • 6,357
  • 9
  • 51
  • 106
ashu
  • 167
  • 2
  • 12
  • 1
    Assuming you create both files in the same directory, how this question does not have your needs? : https://stackoverflow.com/q/1855095/4636715 – vahdet Mar 05 '19 at 07:54

1 Answers1

0

If you want to zip both pdf and csv as single zip file, you can use zipfile or 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 .

Abishek
  • 60
  • 7