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

痞子三分冷 提交于 2019-12-03 06:03:42

You assign something new to images['cover']:

images['cover'] = pic.path_thumb_l

where pic.path_thumb_l is None at some point in your code.

You probably meant to append instead:

images['cover'].append(pic.path_thumb_l)

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']:

Medardo Rodriguez

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)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!