Adding missing close for open and replaced "fid=open(filename) fid.close()"

statements with the safer "with open(filename) as fid:" blocks.

Also removed unnecessary "try: ... finally: pass" statements
and refactored code from img2py function into _write_image and _replace_non_alphanumeric_with_underscore

Fixes #1574
This commit is contained in:
Per A. Brodtkorb
2020-03-24 14:58:24 +01:00
parent f1aaa8b6d3
commit 426258b7b7
16 changed files with 169 additions and 231 deletions

View File

@@ -53,9 +53,8 @@ class NotebookFrame(wx.Frame):
path = dlg.GetPath()
# Open the file as read-only and slurp its content
fid = open(path, 'rt')
text = fid.read()
fid.close()
with open(path, 'rt') as fid:
text = fid.read()
# Create the notebook page as a wx.TextCtrl and
# add it as a page of the wx.Notebook

View File

@@ -53,9 +53,8 @@ class NotebookFrame(wx.Frame):
path = dlg.GetPath()
# Open the file as read-only and slurp its content
fid = open(path, 'rt')
text = fid.read()
fid.close()
with open(path, 'rt') as fid:
text = fid.read()
# Create the notebook page as a wx.TextCtrl and
# add it as a page of the wx.Notebook