mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-07 12:30:07 +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:
@@ -42,19 +42,16 @@ class TablePanel(wx.Panel):
|
||||
|
||||
def ReadData(self):
|
||||
test_file = "./data/testtable.txt"
|
||||
file = open(test_file,'r',1)
|
||||
i = 0
|
||||
|
||||
data = []
|
||||
while 1:
|
||||
text = file.readline()
|
||||
text = text.strip()
|
||||
if not text:
|
||||
break
|
||||
with open(test_file,'r', 1) as file_:
|
||||
data = []
|
||||
for text in file_:
|
||||
text = text.strip()
|
||||
if not text:
|
||||
break
|
||||
|
||||
list_val = text.split('\t')
|
||||
data.append(list_val)
|
||||
file.close()
|
||||
list_val = text.split('\t')
|
||||
data.append(list_val)
|
||||
|
||||
self.header = data[0]
|
||||
self.data = data[1:]
|
||||
|
||||
Reference in New Issue
Block a user