Skip to content

Commit 7b9ee43

Browse files
author
yangjiahua
committed
open file by with to avoid do not close the file if IOError
1 parent 8a0a68c commit 7b9ee43

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Code/1_data_prepare/1_1_cifar10_to_png.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
# 解压缩,返回解压后的字典
1818
def unpickle(file):
19-
fo = open(file, 'rb')
20-
dict_ = pickle.load(fo, encoding='bytes')
21-
fo.close()
19+
with open(file, 'rb') as fo:
20+
dict_ = pickle.load(fo, encoding='bytes')
2221
return dict_
2322

2423
def my_mkdir(my_dir):

0 commit comments

Comments
 (0)