列表变量无法正确读取

时间:2018-10-15 23:50:32

标签: python

所以我已经生成了一个打印在下面的列表;

['Celeste Ng', 'Angie Thomas', 'Gail Honeyman', 'Paula Hawkins', 'Lisa Wingate', 'John 
Green', 'Dan Brown', 'Neil Gaiman', 'Andy Weir', 'Mark T. Sullivan', 'Author', 
'http://www.thewriteteachers.com/wp-content/uploads/2016/06/Image-via-tumblr.com-with- 
steel-toes-980x287.jpg', 'https://www.goodreads.com/book/popular_by_date/2017']

在打印此列表之后的行中,我通过调用列表的元素来调用多次使用它的函数。但是,每当我不断收到此错误时;

<p>Data sourced from """+str(ExtraData[12])+"""</p>
IndexError: list index out of range

我曾尝试降低元素索引来解决问题,但它似乎不适用于任何值。我以前在脚本中使用过该函数四次,并且每次都可以使用。

编辑:这是函数和调用行中的周围的行;

Export(ListData3, ExtraData3, Title, TimeStamp)


"""...<td>10</td>
        <th>"""+str(ListData[9])+"""</th>
        <th>"""+str(ExtraData[9])+"""</th>
           </tr>
        </table>

    <p>Data sourced from """+str(ExtraData[12])+"""</p>

        </div>
</body>
</html>
"""

Exception in Tkinter callback
Traceback (most recent call last):
File 


"C:\Users\Brendan\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:\Users\Brendan\Desktop\ \Study\Uni Shit\Semester 2 2018\IFB104\Assignment 2\the_best_8.4.py", line 611, in BookExport
    Export(ListData3, ExtraData3, Title, TimeStamp)
  File "C:\Users\Brendan\Desktop\ \Study\Uni Shit\Semester 2 2018\IFB104\Assignment 2\the_best_8.4.py", line 233, in Export
    <p>Data sourced from """+str(ExtraData[12])+"""</p>
IndexError: list index out of range

任何帮助将不胜感激, 预先感谢!

1 个答案:

答案 0 :(得分:0)

原来问题不在追溯错误告诉我。事实证明,在该函数中,列表不是所需的长度早于20行。我不确定为什么python告诉我错误的行导致了错误,但现在对其进行了排序。

如果其他人遇到与我相同的问题,请遍历您的代码,打印所有变量的值,以帮助我解决问题。