繁体   English   中英

类型为“ NoneType”的对象没有len():

[英]object of type 'NoneType' has no len() :

def send_ivr_calls(sp_orders, base_url, api_key, extra_data):
    for contact in sp_orders:
        if len(contact) == 10:
            contact = '0'+contact

File "views.py", line 43, in calls if len(contact) == 10:
TypeError: object of type 'NoneType' has no len()

如何检查sp_orders列表是否不包含任何None

尝试这个:

def send_ivr_calls(sp_orders, base_url, api_key, extra_data):
    for contact in sp_orders:
        if contact and len(contact) == 10:
                contact = '0'+contact

这可以确保在尝试获取长度之前,contact并非为None。 感谢@Moses Koledoye指出了短路。

if contact is not None and len(contact) == 10:
    contact = '0'+contact

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM