Python CSV.Writer changing saving path Python CSV.Writer changing saving path tkinter tkinter

Python CSV.Writer changing saving path


Here's an example using tkFileDialog:

import Tkinterimport tkFileDialogimport csvformats = [('Comma Separated values', '*.csv'), ]root = Tkinter.Tk()file_name = tkFileDialog.asksaveasfilename(parent=root, filetypes=formats, title="Save as...")if file_name:    with open(file_name, 'w') as fp:        a = csv.writer(fp)        # write row of header names        a.writerow(n)


Use the tkFileDialog module.

Example:

import tkFileDialogwith open(tkFileDialog.asksaveasfilename(), "w") as fp:    ...


Solution for python3.xxx

   import tkinter   from tkinter.filedialog import asksaveasfilename   with open(asksaveasfilename(), 'w') as fp: