我在Anaconda4.3.1的Spider3.1.4中编辑了三个Python2.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
当我在Spider中“runfile”“a1.py”时,创建了一个TestClass实例tt,并在Spider的IPython控制台中运行以下代码:
>>>tt.getArray()
Out[9]:
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])
它工作正常,但在Spider中运行a2.py文件(空文件)并重新运行tt.getArray格式()”在Spider的IPython控制台中,错误发生:
tt.getArray()
Traceback (most recent call last):
File "<ipython-input-11-50cc0c83ed77>", line 1, in <module>
tt.getArray()
File "TestClass.py", line 6, in getArray
return np.zeros((3,4));
AttributeError: 'NoneType' object has no attribute 'zeros'
numpy丢失了,根据我的经验,Spider中的任何“runfile”操作符都会导致numpy丢失。任何关于“tt”的代码都不能在a2.py中编写,因为tt alread导入的包在运行新文件时丢失。 这是虫子吗?或Spder、Ipython需要进一步配置或设置参数?或者spider中的“runfile”命令需要额外的参数?你知道吗
这个错误使我发疯了,请告诉我哪里出错了。你知道吗
“蜘蛛”是“Spyder”,我拼写有误。你知道吗
Spyder是anaconda的开发环境
由于Spyder有“User Module Reloade(UMR)”属性,我们使用“runfile”函数运行一个脚本,Spyder将重新加载所有用户创建的模块。你知道吗
在我的环境中,Spyder重载TestClass而不是重载numpy,TestClass绑定的numpy被卸载,所以“runfile”可能会导致用户模块无效。你知道吗
在“工具->;首选项->;Python解释器”中,我们可以关闭UMR
相关问题 更多 >
编程相关推荐