“object of type 'NoneType' has no len()” error

前端 未结 3 575
感情败类
感情败类 2021-02-05 08:46

I\'m seeing weird behavior on this code:

images = dict(cover=[],second_row=[],additional_rows=[])

for pic in pictures:
    if len(images[\'cover\']) == 0:
              


        
3条回答
  •  醉梦人生
    2021-02-05 09:42

    your problem is that

    if len(images['cover']) == 0:

    checks the LENGTH of the value of images['cover'] what you meant to do is check if it HAS a value.

    do this instead:

    if not images['cover']:

提交回复
热议问题