我使用的是第三方模块,调用这些模块时出错。 以下是编译器显示的内容:
C:\Users\Dmitry\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site- packages\backtrader\feeds\csvgeneric.py in _loadline(self, linetokens)
148 # get it from the token
149 csvfield = linetokens[csvidx]
--> 150 print(csvidx)
151
152 if csvfield == '':
IndexError: list index out of range
我特意添加了print(csvidx)来查看csvidx的价值,但它并没有显示在控制台上。我做错什么了?谢谢。你知道吗
代码如下:
def _loadline(self, linetokens):
# Datetime needs special treatment
dtfield = linetokens[self.p.datetime]
if self._dtstr:
dtformat = self.p.dtformat
if self.p.time >= 0:
# add time value and format if it's in a separate field
dtfield += 'T' + linetokens[self.p.time]
dtformat += 'T' + self.p.tmformat
dt = datetime.strptime(dtfield, dtformat)
else:
dt = self._dtconvert(dtfield)
if self.p.timeframe >= TimeFrame.Days:
# check if the expected end of session is larger than parsed
if self._tzinput:
dtin = self._tzinput.localize(dt) # pytz compatible-ized
else:
dtin = dt
dtnum = date2num(dtin) # utc'ize
dteos = datetime.combine(dt.date(), self.p.sessionend)
dteosnum = self.date2num(dteos) # utc'ize
if dteosnum > dtnum:
self.lines.datetime[0] = dteosnum
else:
# Avoid reconversion if already converted dtin == dt
self.l.datetime[0] = date2num(dt) if self._tzinput else dtnum
else:
self.lines.datetime[0] = date2num(dt)
# The rest of the fields can be done with the same procedure
for linefield in (x for x in self.getlinealiases() if x != 'datetime'):
# Get the index created from the passed params
csvidx = getattr(self.params, linefield)
if csvidx is None or csvidx < 0:
# the field will not be present, assignt the "nullvalue"
csvfield = self.p.nullvalue
else:
# get it from the token
print(csvidx)
csvfield = linetokens[csvidx]
if csvfield == '':
# if empty ... assign the "nullvalue"
csvfield = self.p.nullvalue
# get the corresponding line reference and set the value
line = getattr(self.lines, linefield)
line[0] = float(float(csvfield))
return True
csvidx
正在self.params
中被寻找,很明显它正在被发现。你知道吗它似乎既不是
None
也不是< 0
,所以它似乎有一个数值>= 0
IndexError: list index out of range
清楚地表明linetokens
没有包含csvidx
所期望的那么多项。你知道吗由于名称
self.params
似乎表示用户输入,因此您给出的任何值似乎都大于linetokens
中可用的令牌的实际数量这些代码似乎是在一个封闭的Python环境中执行的
因为这肯定不是通常的Python控制台输出。如果这个封闭的环境(而不是第三方软件包)真的允许您
print
到控制台,那么实际上应该更早地完成,如:您应该在触发异常之前查看每个关系
linefield
->;csvidx
。你知道吗如果您的环境允许,可以使用
python -u
运行所有的东西,它使用无缓冲输出。(强烈建议在新行刷新不起作用或有问题的窗口下使用)相关问题 更多 >
编程相关推荐