Преглед изворни кода

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