소스 검색

Update util.py

refactor with With statement to open file to make code more Pythonic
anonymousdouble 1 년 전
부모
커밋
82dc203f40
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      tests/labelme_tests/utils_tests/util.py

+ 2 - 1
tests/labelme_tests/utils_tests/util.py

@@ -10,7 +10,8 @@ data_dir = osp.join(here, "../data")
 
 def get_img_and_data():
     json_file = osp.join(data_dir, "annotated_with_data/apc2016_obj3.json")
-    data = json.load(open(json_file))
+    with open(json_file) as f:
+        data = json.load(f)
     img_b64 = data["imageData"]
     img = image_module.img_b64_to_arr(img_b64)
     return img, data