小编给大家分享一下python随机读取目录文件的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
python随机读取目录文件的方法:使用python的模块random argparse shutil,代码为【for x in os.listdir(path),if x.endswith('jpg')】。
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")
看完了这篇文章,相信你对python随机读取目录文件的方法有了一定的了解,想了解更多相关知识,欢迎关注创新互联-成都网站建设公司行业资讯频道,感谢各位的阅读!
网站题目:python随机读取目录文件的方法-创新互联
转载来源:https://www.cdcxhl.com/article44/ihpee.html
成都网站建设公司_创新互联,为您提供商城网站、网站制作、做网站、网站导航、云服务器、营销型网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联