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
个?
答案 0 :(得分:3)
试试这个:
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
这可以确保在您尝试获取其长度之前,联系不是“无”。感谢@Moses Koledoye指出短路。
答案 1 :(得分:1)
if contact is not None and len(contact) == 10:
contact = '0'+contact