@app.route('/')
def index():
tpopDloads = popDloads
tpopShipped = popShipped
locPopDload = []
locPopShipped = []
popDinfo = []
popSinfo = []
popDloadsOrd = sorted(tpopDloads, reverse=True)
popShippedOrd = sorted(tpopShipped, reverse=True)
for i in range(3):
locPopDload.append(tpopDloads.index(popDloadsOrd[i]))
popDinfo.append(dProducts[locPopDload[i]])
tpopDloads[tpopDloads.index(popDloadsOrd[i])] = -1 #Problem line#
for i in range(3):
locPopShipped.append(tpopShipped.index(popShippedOrd[i]))
popSinfo.append(sProducts[locPopShipped[i]])
tpopShipped[tpopShipped.index(popDloadsOrd[i])] = -1
return render_template('index.html', popDinfo=popDinfo, popSinfo=popSinfo)
我得到的错误是:
File "/var/lib/openshift/5697165a0c1e66eb870000fb/app-root/runtime /repo/flaskapp.py", line 47, in index
tpopShipped[tpopShipped.index(popDloadsOrd[i])] = -1
ValueError: 0 is not in list
这是使用两个变量popDloads和popShipped,它们都是包含一组整数的列表。我不明白为什么它没有工作,因为在订购列表后它试图找到一个数字的实际索引。它也适用于数字全为零的情况,只有在我更改了另一段代码中的数字后才会出现问题。
答案 0 :(得分:0)
错误告诉您代码无法正常工作的原因。 0
不在tpopShipped
列表中。{/ 1>
>>> [1,2,3].index(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 0 is not in list