0

我最近遇到了类似的错误:

IndexError                                Traceback (most recent call last)
<ipython-input-124-59ca523b1b36> in <module>()
----> 1 first_experiment_comb(model)

  c:\python26\26664\lib\site-packages\experiments.py in first_experiment_comb(mod
 l)
     172                      "Number NZ: " + str(modelz[j].NumNZs) +"\n")
     173
 --> 174         first_experiment(modelz[j], str(j))
     175
     176

c:\python26\26664\lib\site-packages\experiments.py in first_experiment(model, e
t)
     89         plt.close()
     90
---> 91     fl.timberFlow(model)
     92     plt.savefig(dire + "\\timber_flow" +ext+".pdf", bbox_inches = 0)
     93     plt.close()

C:\Python26\26664\lib\site-packages\func_lib.py in timberFlow(model)
    304     if not unVars:
    305         unVars = varValues(model, 'PIEHTLVOL')
--> 306
    307     for i in range(19):
    308             swVarVals.append(swVars[i].X)

IndexError: list index out of range

跟踪的最后一行指向不存在的代码,或者在以前的情况下已被注释掉。当我自己运行最后一个函数(在func_lib.py中)时,我永远不会得到神秘的IndexError,只有当它从experiments.py调用时。

我在 pylab python 2.6 W64 中运行它。我无法在 iPython 或 Pylab 文档中找到关于此的已知错误。

第 306 行怎么可能是错误的根源?

4

1 回答 1

3

您的代码与字节码不同步。正确重新加载您的代码。

发生异常时,会检查字节码中的文件名和行号,然后加载源文件以显示该行的原始源。

但是,如果您更改了源代码但尚未重新启动您的 python 进程(或重新加载 ipython 中的代码),那么当发生异常时会显示错误的行。

于 2013-03-14T21:44:39.567 回答