【发布时间】:2017-10-19 02:15:53
【问题描述】:
我在 Anaconda 4.3.1 的 Spyder 3.1.4 中编辑了三个 python 2.7 文件
(1). TestClass.py :Just define a class
import numpy as np
class TestClass:
def getArray(self):
return np.zeros((3,4));
(2). a1.py
from TestClass import *;
tt=TestClass();
(3). a2.py
#just a empty python file
当我在 Spyder 中“运行文件”“a1.py”时,会创建一个 TestClass 实例 tt,然后我在 Spyder 的 IPython 控制台中运行以下代码:
tt.getArray()
Out[9]:
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])
它可以正常工作,但是在我在 Spider 中运行文件 a2.py(一个空文件)并在 Spyder 的 IPython 控制台中重新运行“tt.getArray()”之后,出现了错误:
tt.getArray() Traceback(最近一次调用最后一次):
文件“”,第 1 行,在 tt.getArray()
文件“TestClass.py”,第 6 行,在 getArray 中 返回 np.zeros((3,4));
AttributeError: 'NoneType' 对象没有属性 'zeros' numpy 丢失了,根据我的经验,Spyder 中的任何“运行文件”运算符都会导致丢失 numpy。任何关于“tt”的代码都不能写在 a2.py 中,因为 tt alread 导入的包在运行新文件时丢失。这是一个错误吗?还是 Spyder、Ipython 需要进一步配置或设置参数?还是spyder中的“runfile”命令需要额外的参数?
我被这个错误弄疯了,请告诉我哪里出错了。
【问题讨论】:
标签: model load ipython anaconda spyder