您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

python如何随机读取目录文件

2025/5/20 13:12:42发布26次查看
python随机读取目录文件的方法是使用python的模块【random argparse shutil】读取即可,其代码语句为【for x in os.listdir(path),if x.endswith('jpg')】。
python随机读取目录文件的方法:
使用python模块:random argparse shutil
import argparseparser = argparse.argumentparser()parser.add_argument('num',type=int,help="img numbers to random")args = parser.parse_args()import randomimport ospath="/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 copyfilefor img in selected_imgs: src=os.path.join(path,img) dst=os.path.join(path,"../for_bitmain/"+img) copyfile(src,dst)print("copy done")
相关学习推荐:python教程
以上就是python如何随机读取目录文件的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product