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

前端 未结 3 566
感情败类
感情败类 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:27

    The first time you assign: images['cover'] = pic.path_thumb_l, it replaces the value of the empty list initially stored in images['cover'] with the value of pic.path_thumb_l which is None.

    Maybe your code in this line must be images['cover'].append(pic.path_thumb_l)

提交回复
热议问题