簡體   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