【发布时间】:2020-03-10 03:10:38
【问题描述】:
我试图在这些循环中创建变量,但 python 给了我一个语法错误。 tme 和 empty 都给我这个问题。我试图让 python 读取一个 excel 表并将值放在一个列表中。我试图创建的变量应该可以帮助我在 python 中找到空格并从我创建的另一个列表中删除值,以便我获得的值对应于正确的输入,并且在 excel 中没有值的输入被删除从那个列表中。如果有修复程序,它也会给出索引错误,我会很感激,但我可以弄清楚变量是否正常工作。
span = list()
print(span)
price = list() #creates a list with all the values before giving index error
for q in range(1,chart.nrows):
for i in range (1,chart.ncol):
L = (chart.cell_value(q,i))
if L != '': #all values that exist will be appended to the list
price.append(L)
else: #find x and y parts of space, have that popped from span list
moth = chart.cell_value(q,0)
m = str(moth)
y = year = str(chart.cell_value(0,i)
tme = m + ' ' + y
empty = span.index(tme)
span.pop(empty)
【问题讨论】:
标签: python python-3.x variables syntax index-error