[Tutor] Writing logfile data to a user opened file
Matt D
md123 at nycap.rr.com
Sat Jun 22 03:42:53 CEST 2013
>
> You should really switch to the "with open() as f:" idiom I keep showing
> you. This will automatically close the file for you.
>
it just occured to me to do this:
def openFile(self, evt):
with wx.FileDialog(self, "Choose a file", os.getcwd(), "",
"*.txt*", wx.OPEN) as dlg:
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
mypath = os.path.basename(path)
with open(mypath, "a") as f:
f.writelines(self.log_array)
so thats how i used what you said, "with open() as f:". is this the
right way to open the file?
More information about the Tutor
mailing list