python随机选取目录下的若干个文件
作者:互联网
个人记录用. python模块random argparse shutil
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('num',type=int,help="img numbers to random")
args = parser.parse_args()
import random
import os
path="/home/train/disk/data/yulan_park_expand"
imgs = []
for x in os.listdir(path):
if x.endswith('jpg'):
imgs.append(x)
selected_imgs=random.sample(imgs,k=args.num)
print(selected_imgs)
from shutil import copyfile
for img in selected_imgs:
src=os.path.join(path,img)
dst=os.path.join(path,"../for_bitmain/"+img)
copyfile(src,dst)
print("copy done")
标签:img,python,random,选取,import,imgs,path,os,若干个 来源: https://www.cnblogs.com/sdu20112013/p/11084151.html