[Tutor] Writing logfile data to a user opened file

Matt D md123 at nycap.rr.com
Sat Jun 22 17:16:01 CEST 2013


On 06/22/2013 03:47 AM, Alan Gauld wrote:
> On 22/06/13 02:42, Matt D wrote:
> 
>>              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?
> 
> You need to indent the writelines() call so its inside
> the 'with' block.
> 
>                   with open(mypath, "a") as f:
>                        f.writelines(self.log_array)
> 
> This means you don't need to call f.close() each time - which you were
> missing from your earlier code.
> 
Thanks!  That is how i had it; not sure how the indent got nixed when
pasted to my mail.


More information about the Tutor mailing list