Skip to content

Commit d7012e9

Browse files
committed
Close file write
1 parent 70682c2 commit d7012e9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

label_maker/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def download_tile_tms(tile, imagery, folder, *args):
3030
_, image_format = op.splitext(o.path)
3131
r = requests.get(url(tile.split('-'), imagery))
3232
tile_img = op.join(folder, '{}{}'.format(tile, image_format))
33-
open(tile_img, 'wb').write(r.content)
33+
with open(tile_img, 'wb')as w:
34+
w.write(r.content)
3435
return tile_img
3536

3637
def get_tile_tif(tile, imagery, folder, imagery_offset):
@@ -109,7 +110,8 @@ def get_tile_wms(tile, imagery, folder, imagery_offset):
109110
wms_url = imagery.replace('{bbox}', ','.join([str(b) for b in bbox]))
110111
r = requests.get(wms_url)
111112
tile_img = op.join(folder, '{}.{}'.format(tile, image_format))
112-
open(tile_img, 'wb').write(r.content)
113+
with open(tile_img, 'wb') as w:
114+
w.write(r.content)
113115
return tile_img
114116

115117

0 commit comments

Comments
 (0)