1. 程式人生 > >Python使用心得

Python使用心得

這個方法可以獲得資料夾下的所有路徑。 跟os.walk(dir)相似, pos_file_path_list是map型別的,一行程式碼就解決了,比較方便


    pos_file_path_list = map(lambda x: os.path.join(POS_IMAGE_DIR, x), os.listdir(POS_IMAGE_DIR))
    neg_file_path_list = map(lambda x: os.path.join(NEG_IMAGE_DIR, x), os.listdir(NEG_IMAGE_DIR))
    # 獲取圖片列表
    # 調整圖片大小
    for index, pic in enumerate(pos_file_path_list):
        f_out = os.path.join(RESIZE_POS_IMAGE_DIR, '{}.{}'.format(index, IMG_TYPE))
        resize_image(pic, f_out, IMG_WIDTH, IMG_HEIGHT)