mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-06 20:10:08 +01:00
Fixes issue 1571:
Adding missing close for open. If the "close()" call is missing after a "open(filename)" call, the filename isn't guaranteed to be closed before the interpreter exits. This is generally a bad practice as explained here: https://stackoverflow.com/questions/7395542/is-explicitly-closing-files-important Also replaced "fid=open(filename) fid.close()" statements for files with the safer "with open(filename) as fid:" blocks. See https://www.python.org/dev/peps/pep-0343/
This commit is contained in:
@@ -76,21 +76,17 @@ class DoodleFrame(wx.Frame):
|
||||
# size events using this sizer.
|
||||
self.SetSizer(box)
|
||||
|
||||
|
||||
def SaveFile(self):
|
||||
if self.filename:
|
||||
data = self.doodle.GetLinesData()
|
||||
f = open(self.filename, 'wb')
|
||||
pickle.dump(data, f)
|
||||
f.close()
|
||||
|
||||
with open(self.filename, 'wb') as f:
|
||||
pickle.dump(data, f)
|
||||
|
||||
def ReadFile(self):
|
||||
if self.filename:
|
||||
try:
|
||||
f = open(self.filename, 'rb')
|
||||
data = pickle.load(f)
|
||||
f.close()
|
||||
with open(self.filename, 'rb') as f:
|
||||
data = pickle.load(f)
|
||||
self.doodle.SetLinesData(data)
|
||||
except pickle.UnpicklingError:
|
||||
wx.MessageBox("%s is not a doodle file." % self.filename,
|
||||
|
||||
Reference in New Issue
Block a user