我在为科学计算做模拟,我几乎总是想在交互式解释器中查看我的模拟输出。我正试图编写类来定义模拟对象(神经种群),我想通过调用ipython中的脚本%run test_class_WC.py来规范我对这些类的测试。由于包含类的模块/文件在我尝试调试它/添加功能时正在更改,所以每次都会重新加载它。
/试验等级:import WC_class # make sure WC_class exists
reload(WC_class) # make sure it's the most current version
import numpy as np
from WC_class import WC_unit # put the class into my global namespace?
E1 = WC_unit(Iapp=100)
E1.update() # see if it works
print E1.r
所以现在我正在使用reload来确保我已经加载了模块的最新版本,所以我得到了最新的类定义——我确信这是一个笨拙的heck(或者更邪恶的?),但它省去了我做%run WC_class.py和单独调用%run test_WC.py的麻烦
和/WC_类:class WC_unit:
nUnits = 0
def __init__(self,**kwargs):
self.__dict__.update(dict( # a bunch of params
gee = .6, # i need to be able to change
ke=.1,the=.2, # in test_class_WC.py
tau=100.,dt=.1,r=0.,Ia