我有一个返回列表的函数。但是它没有任何回报。我想处理TypeError。 我已经尝试过了:
def isLookingAround(lst):
res = []
body = []
for data in lst:
res += isLookingAt(normalize2(data))
body += isBodyDirection(normalize2(data))
if most_body == "front" or most_body == "backward":
if ('lookL' in res and 'lookR' in res):
return 'lookingAround'
elif most_body == "left" or most_body == "right":
if ('lookF' in res and 'lookB' in res):
return 'lookingAround'
错误:
Traceback (most recent call last):
File "action_detector.py", line 201, in <module>
write_labels(input_source, labels)
File "action_detector.py", line 179, in write_labels
for itr, word in enumerate(lbls):
TypeError: 'NoneType' object is not iterable
我仍然遇到label.append(detectors.isLookingAround(back_Data))的错误。感谢您的帮助。
答案 0 :(得分:0)
要检查数据是否为空。您可以使用以下代码
if data:
l.append(data)
答案 1 :(得分:-1)
为了处理NoneType
异常,可以将语句放在try-except
块内。
例如,您可以执行类似的操作
try:
labels.append(detectors.isLookingAround(back_Data))
except TypeError:
# Do something. Like,
return
它将“捕获”错误,然后您可以正确处理它。但是,该错误似乎来自isLookingAround
方法。
您可以重新检查,如果无法解决,我想发布一个新问题。