我有一个network.py
包含以下内容的脚本:
from brian import *
. . .
simulation_clock = Clock(dt=dt)
. . .
pop_vector = NeuronGroup(1, model=eqs_pop_vector)
此脚本引发TypeError
, 因为simulation_clock
未作为参数传递给NeuronGroup
.
但是,如果我按如下方式拆分我的代码
$ cat simclock.py
simulation_clock = Clock(dt=dt)
$ cat network.py
from brian import *
. . .
execfile('simclock.py')
. . .
pop_vector = NeuronGroup(1, model=eqs_pop_vector)
它运行顺利 - 即,没有TypeError
。
我的问题的答案可能部分与 的细节有关NeuronGroup
,但它也比这更笼统:为什么通常相同的确切代码- 在这种情况下simulation_clock = Clock(dt=dt)
- 与其余代码并execfile
在与其余代码相同的脚本中调用时?
关于 的细节NeuronGroup
,当提供 no 作为参数时,将调用以下函数(使用默认关键字参数)Clock
,以查找 的已定义实例Clock
:
def find_instances(instancetype, startlevel=1, all=False):
"""Find first instances of a given class in the stack
See documentation for module Brian.magic
"""
# Note that we start from startlevel+1 because startlevel means from the calling function's point of view
for level in range(startlevel + 1, len(getouterframes(currentframe()))):
objs, names = get_instances(instancetype, level, all=all)
if len(objs):
return (objs, names)
return ([], [])
由于某种原因,此函数无法找到在以 .Clock
调用的单独文件中定义的实例execfile
。所以我想这是一个brian
引起普遍问题的错误。(如果社区觉得这个问题太具体,我会删除它。)