利用Python随机删除一半数量的图片

利用Python随机删除一半数量的图片

import os
import random

num = 0;
for image_name in os.listdir("./data"):
    feed = random.randint(0, 10)
    if feed <= 5:
        os.remove(os.path.join("./data", image_name));
        print(feed)
        print(os.path.join("./data", image_name))
        num = num + 1
print(num)

 

posted @ 2020-05-28 09:31  cumtchw  阅读(555)  评论(0编辑  收藏  举报