我希望通过一个文件迭代到每行上的所选索引,但即使行上的变量比我选择的索引多,我也会收到这个错误。
for thing in lines:
item = thing.split(',')
**price = item[4]**
total_Stock_Value = total_Stock_Value + float(price)
print('Total Value of Books in Stock: £{:0,.2f}'.format(total_Stock_Value,'n'))
检查文件末尾是否有空换行符,这是发生这种情况的常见位置。出现错误是有原因的,所以一定有一行没有足够的逗号。