Skip to content

Commit b5a9df9

Browse files
BoboTiGaymericdamien
authored andcommitted
Fix ResourceWarning: unclosed file (aymericdamien#295)
Signed-off-by: Mickaël Schoentgen <[email protected]>
1 parent 796de7c commit b5a9df9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

examples/5_DataManagement/build_an_image_dataset.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def read_images(dataset_path, mode, batch_size):
5656
imagepaths, labels = list(), list()
5757
if mode == 'file':
5858
# Read dataset file
59-
data = open(dataset_path, 'r').read().splitlines()
59+
with open(dataset_path) as f:
60+
data = f.read().splitlines()
6061
for d in data:
6162
imagepaths.append(d.split(' ')[0])
6263
labels.append(int(d.split(' ')[1]))

notebooks/5_DataManagement/build_an_image_dataset.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
" imagepaths, labels = list(), list()\n",
8585
" if mode == 'file':\n",
8686
" # Read dataset file\n",
87-
" data = open(dataset_path, 'r').read().splitlines()\n",
87+
" with open(dataset_path) as f:\n",
88+
" data = f.read().splitlines()\n",
8889
" for d in data:\n",
8990
" imagepaths.append(d.split(' ')[0])\n",
9091
" labels.append(int(d.split(' ')[1]))\n",

0 commit comments

Comments
 (0)