当用作上下文管理器时,NpzFile是否正在关闭自身?

2024-03-29 00:38:02 发布

您现在位置:Python中文网/ 问答频道 /正文

numpy.load()的docstring中,我发现了以下警告:

For .npz files, the returned instance of NpzFile class must be closed to avoid leaking file descriptors.

我注意到,返回的NpzFile对象同时具有__enter__()__exit__()方法。你知道吗

如果我这样使用它,它会自动关闭吗:

>>> with numpy.load('my_mile.npz') as data:
...     A = data['A']

什么?你知道吗


Tags: oftheinstancenumpy警告fordataload