python中的斷言assert

可以用來檢測變量是否達到要求
比如

    # check if h and w in record equals that read from img
    assert img.shape[0] == int(h), \
        "image height of {} inconsistent in record({}) and img file({})".format(
            im_file, h, img.shape[0])

當圖片的尺寸h和已知的h不同
","後面的東西表示,如果發生錯誤輸出的東西
\是分段符,沒有實際作用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章