Reputation: 7428
I am using wx.FileDialog
to pop a directory select dialog for the user to choose the save path. The file type I'd like to save is .csv
files.
Here is the code:
fdlg = wx.FileDialog(self.panel_settings, "Input setting file path", "", "", "CSV files(*.csv)|*.*", wx.FD_SAVE)
if fdlg.ShowModal() == wx.ID_OK:
self.save_path = fdlg.GetPath() + ".csv"
with open(self.save_path, "wb") as file:
writer = csv.writer(file, delimiter = ',')
When a dialog pops up, I simply type in test
as the file name. As I click OK
button, it directly save an empty test.csv
file.
However, what I want to do is just keep the input path and file name, then write the content myself.
So, may I know how to work around this?
Thanks.
Upvotes: 1
Views: 3911
Reputation: 2344
wx.FileDialog does not create the file, it returns the path. You are creating the file with this code:
with open(self.save_path, "wb") as file:
writer = csv.writer(file, delimiter = ',')
Upvotes: 3