【发布时间】:2021-09-05 19:41:33
【问题描述】:
np.__version__
Out[307]: '1.20.1'
np.loadtxt 抛出 enter 错误
with np.loadtxt("textfile.txt",delimiter=",") as data1:
...: print ("Hello")
...:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-300-05181e15f7ec> in <module>
----> 1 with np.loadtxt("textfile.txt",delimiter=",") as data1:
2 print ("Hello")
AttributeError: __enter__
相同的类,即 np 不会在 load 时抛出 enter 错误。 我想知道 enter 和 exit 是如何绑定到一个类的
with np.load("new.txt.npz") as data:
...: print (data["a"])
...:
...:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]
[12 13 14 15]]
【问题讨论】:
标签: python arrays numpy load enter