From efe04c8205e39d1edfe206df1c865c99bbd3af66 Mon Sep 17 00:00:00 2001 From: David Cournapeau Date: Mon, 10 Oct 2011 09:09:45 +0100 Subject: DOC: mention that NpzFile instances must be closed. --- numpy/lib/npyio.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'numpy/lib') diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index cb71ffad5..07a8ca429 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -285,7 +285,8 @@ def load(file, mmap_mode=None): Returns ------- result : array, tuple, dict, etc. - Data stored in the file. + Data stored in the file. For '.npz' files, the returned instance of + NpzFile class must be closed to avoid leaking file descriptors. Raises ------ @@ -315,6 +316,17 @@ def load(file, mmap_mode=None): array([[1, 2, 3], [4, 5, 6]]) + Store compressed data to disk, and load it again: + + >>> np.savez('/tmp/123.npz', a=np.array([[1, 2, 3], [4, 5, 6]]), b=np.array([1, 2])) + >>> data = np.load('/tmp/123.npy') + >>> data['a'] + array([[1, 2, 3], + [4, 5, 6]]) + >>> data['b'] + array([1, 2]) + >>> data.close() + Mem-map the stored array, and then access the second row directly from disk: -- cgit v1.2.1