我在这段代码上看到了奇怪的行为:
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)
我的 web2py 应用程序给我这个错误:
if len(images['cover']) == 0: TypeError: object of type 'NoneType' has no len()
我不明白这是怎么回事。也许是一些范围问题?
最佳答案
你给 images['cover']
分配了一些新的东西:
images['cover'] = pic.path_thumb_l
在您的代码中,pic.path_thumb_l
是 None
。
您可能打算改为附加:
images['cover'].append(pic.path_thumb_l)
关于python - "object of type ' 无类型 ' has no len()"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11816844/