Skip to content

Commit ba80cfb

Browse files
author
Marina Samuel
committed
Use a context manager for loading the neural network file.
1 parent 0a8c40d commit ba80cfb

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

ocr/ocr.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ def save(self):
125125
nnFile.close()
126126

127127
def _load(self):
128-
nnFile = open(ocrNeuralNetwork.NN_FILE_PATH);
129-
nn = json.load(nnFile)
128+
with open(ocrNeuralNetwork.NN_FILE_PATH) as nnFile:
129+
nn = json.load(nnFile)
130130
self.theta1 = [np.array(li) for li in nn['theta1']]
131131
self.theta2 = [np.array(li) for li in nn['theta2']]
132132
self.input_layer_bias = [np.array(nn['b1'][0])]
133133
self.hidden_layer_bias = [np.array(nn['b2'][0])]
134-
nnFile.close()

0 commit comments

Comments
 (0)