列表变量未正确读取

2024-04-19 01:41:01 发布

您现在位置: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

任何帮助都将不胜感激, 提前谢谢!你知道吗


Tags: 函数infrompycom列表dataexport
1条回答
网友
1楼 · 发布于 2024-04-19 01:41:01

原来问题不在回溯错误告诉我的那条线上。结果是在函数前面的20行中,列表不是所需的长度。我不知道为什么python告诉我错误的行导致了错误,但是它现在已经排序了。你知道吗

如果其他人和我有同样的问题,请运行代码打印所有变量的值,因为这有助于我解决问题。你知道吗

相关问题 更多 >