IndexError: list index out of ra

作者: 一枚小黑 | 来源:发表于2017-11-06 19:41 被阅读0次

如题,对index这种的异常处理的解决方法有以下两种:

1、 用 try捕获处理

'''
    try:
        href = response.meta['href']
    except INdexError:
        href = 'null'
'''

2、用len()做个判断

'''
     href = dlist[1] if len(dlist) > 1 else 'null'
'''

相关文章

网友评论

    本文标题:IndexError: list index out of ra

    本文链接:https://www.haomeiwen.com/subject/btqrmxtx.html