diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2019-06-26 10:43:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-26 10:43:36 -0700 |
commit | df096f8386cb1478e117fc959c3c3c374fb1895b (patch) | |
tree | 6f716b3d39fc6305ac4b7c0a489bbe693b258c0d /numpy/lib/format.py | |
parent | 113560b576c57fcbaa758cb8e7b12b7f19f51c2f (diff) | |
parent | 4262579fe671bad09aefa1716f45c73023011048 (diff) | |
download | numpy-df096f8386cb1478e117fc959c3c3c374fb1895b.tar.gz |
Merge branch 'master' into force-zip64
Diffstat (limited to 'numpy/lib/format.py')
-rw-r--r-- | numpy/lib/format.py | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py index a14f3e4b2..93bdbce97 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -840,16 +840,12 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, shape=shape, ) # If we got here, then it should be safe to create the file. - fp = open(os_fspath(filename), mode+'b') - try: + with open(os_fspath(filename), mode+'b') as fp: _write_array_header(fp, d, version) offset = fp.tell() - finally: - fp.close() else: # Read the header of the file first. - fp = open(os_fspath(filename), 'rb') - try: + with open(os_fspath(filename), 'rb') as fp: version = read_magic(fp) _check_version(version) @@ -858,8 +854,6 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, msg = "Array can't be memory-mapped: Python objects in dtype." raise ValueError(msg) offset = fp.tell() - finally: - fp.close() if fortran_order: order = 'F' |