“'NoneType' 类型的对象没有 len()";错误 [英] "object of type 'NoneType' has no len()" error

查看:36
本文介绍了“'NoneType' 类型的对象没有 len()";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这段代码上看到了奇怪的行为:

images = dict(cover=[],second_row=[],additional_rows=[])对于图片中的图片:如果 len(images['cover']) == 0:图像['封面'] = pic.path_thumb_lelif len(images['second_row']) <3:图像['second_row'].append(pic.path_thumb_m)别的:图像['additional_rows'].append(pic.path_thumb_s)

我的 web2py 应用程序给了我这个错误:

<块引用>

if len(images['cover']) == 0:类型错误:NoneType"类型的对象没有 len()

我无法弄清楚这有什么问题.也许是范围问题?

解决方案

您为 images['cover'] 分配新的内容:

images['cover'] = pic.path_thumb_l

其中 pic.path_thumb_l 在代码中的某个点是 None.

您可能打算改为附加:

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

I'm seeing weird behavior on this code:

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

for pic in pictures:
    if len(images['cover']) == 0:
        images['cover'] = pic.path_thumb_l
    elif len(images['second_row']) < 3:
        images['second_row'].append(pic.path_thumb_m)
    else:
        images['additional_rows'].append(pic.path_thumb_s)

My web2py app gives me this error:

if len(images['cover']) == 0:
TypeError: object of type 'NoneType' has no len()

I can't figure out what's wrong in this. Maybe some scope issue?

解决方案

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)

这篇关于“'NoneType' 类型的对象没有 len()";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆