TypeError:类型为'NoneType'的对象在我的python代码中没有len()

这是我的python代码:

if len(contours) >= 2:
            old_center[0] = center[0]
            if is_mouse_down:
                Thread(target=gui.mouseUp, args=()).start()
                is_mouse_down = False
评论
  • mnam
    mnam 回复

    Here, countours is None, as None is not iterable so it doesn't have len too. You can modify your logic like :

    if contours and len(contours) >= 2:
        old_center[0] = center[0]
        if is_mouse_down:
            Thread(target=gui.mouseUp, args=()).start()
            is_mouse_down = False